Php 对对象属性的引用
是否可以创建引用其自身对象属性的变量Php 对对象属性的引用,php,oop,properties,reference,Php,Oop,Properties,Reference,是否可以创建引用其自身对象属性的变量 <?php class MyClass { public $num_of_call=array(); public function call($number) { if(!isset($this->num_of_call[$number])) { $this->num_of_call[$number] = 1; return; } $c
<?php
class MyClass
{
public $num_of_call=array();
public function call($number)
{
if(!isset($this->num_of_call[$number]))
{
$this->num_of_call[$number] = 1;
return;
}
$counter &= $this->num_of_call[$number];
$counter++;
}
}
$var&=$value
——它是$var=$var&$value
的缩写
您需要这样做:
$counter = &$this->num_of_call[$number];
$var&=$value
——它是$var=$var&$value
的缩写
您需要这样做:
$counter = &$this->num_of_call[$number];