PHP =& new 使用注意事項

023 月

PHP =& new 使用注意事項

 

注意 PHP 5.3 之後的版本,是已經建議廢棄 =& new 但不是所有情況的 =& 都不建議了
若原來為 =& new 則改為 = new 就好,若原來為 =& xxx::aa() 則可以不用更動

Deprecated features in PHP 5.3.x
http://tw2.php.net/manual/en/migration53.deprecated.php

引用

Assigning the return value of new by reference is now deprecated.

 

php5以後object是by reference
程式碼:

<?php
class a{
  public $a=null;
}

$a=new a();
$b=$a;
$a->a=123;
echo $b->a;
-----
output:
123

=new 的意義等同於=& new

xxx::aa()
是靜態的指定,在php內部是重新指派一個資源
所以=&xxx::aa()還是有存在的必要

Posted by admin  Posted on 02 3 月 
  • PHP
  • Post Comments 0