相关疑难解决方法(0)

为什么全局函数为空?

我遇到了这个奇怪的问题....

所有页面都只有这个代码.global $ currentPage; 是null,我不知道为什么......

<?php
$pager = $_PARAMS["this"];
$pages = 5;
$currentPage = 1;
$tst="ap";
$nearPages = 5;
//Prologic
?>
<div class="pager">
<?php
$nearPagesHalf = ($nearPages - 1) / 2;

drawNumbers(1, 1);
if ($currentPage - $nearPagesHalf <= 0) {

}

drawNumbers($pages, $pages);
?> 

    <?php

    function drawNumbers($from, $to) {
        global $currentPage;



        for ($i = $from; $i <= $to; $i++) {

            echo $currentPage;

            if ($i == $currentPage) {
    ?> <span class="pageNumbers current"><?= $i ?></span>

    <?php
            } else {
    ?>
                <a href="#"> …
Run Code Online (Sandbox Code Playgroud)

php

9
推荐指数
2
解决办法
8083
查看次数

使用PHPUnit时,全局变量为null

我将PHPUnit测试放入现有项目中.全局常量变量被广泛使用.在我的单元测试函数失败,因为全局变量为null.这是一个失败测试的例子

static $secret_key = "a secret Key";
class secret_key_Test extends PHPUnit_Framework_TestCase
{
    function test_secret_key()
    {
        global $secret_key; 
        $this->assertEquals($secret_key, "a secret Key");   
    }
}

>> Failed asserting that 'a secret Key' matches expected null
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

更新:我尝试删除静态和添加

protected $backupGlobals = FALSE;
Run Code Online (Sandbox Code Playgroud)

对班级宣言没有成功.

php phpunit

9
推荐指数
2
解决办法
8596
查看次数

标签 统计

php ×2

phpunit ×1