Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 339

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 392

Deprecated: parse_url(): Passing null to parameter #1 ($url) of type string is deprecated in /www/wwwroot/blog_qqvbc_com/usr/plugins/Access/Access_Core.php on line 394
PHP 在写类和函数的时候,方法名前加了&符号,是什么意思呢? - Joyber 的博客

分别执行下面的两个代码,看看结果是什么:http://www.dooccn.com/php7/#id/21a18721ff4c0d013dcef162d57bbb15

<?php
    function &test(){
    static $b = 0;  //声明一个静态变量
    $b = $b+1;
    echo $b;
    return $b;
    }
   $a = test();   //输出 $b 的值为:1
   $a = 5;
   $a = test();     //输出 $b 的值为:2
   
   $a = &test();  //输出 $b 的值为:3  **注意**
   $a = 5;           //$b的值变为了5
   $a = test();    //输出 $b 的值为:6  **注意**
?>
<?php
    function test(){
    static $b = 0;  //声明一个静态变量
    $b = $b+1;
    echo $b;
    return $b;
    }
   $a = test();   //输出 $b 的值为:1
   $a = 5;
   $a = test();     //输出 $b 的值为:2
   
   $a = &test();  //输出 $b 的值为:3  **注意**
   $a = 5;           //$b的值变为了5
   $a = test();    //输出 $b 的值为:6  **注意**
?>

标签: php

添加新评论