note 82832 deleted from control-structures.alternative-syntax by mgf
| From: | mgf@php.net | Date: | Thu, 28 Aug 2008 12:48:03 +0000 |
| Subject: | note 82832 deleted from control-structures.alternative-syntax by mgf | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143925@lists.php.net to get a copy of this message | ||
Note Submitter: protractor at gmx dot net
----
If you use alternative syntax beware that references will be broken.
I hope this helps someone.
example:
<?php
class myclass
{
public $arr = NULL;
public function &get($name) // should return a reference
{
return isset($this->arr[$name]) ? $this->arr[$name] : NULL;
}
public function &get_by_ref($name) // returns a reference
{
if(isset($this->arr[$name]))
{
return $this->arr[$name];
}else{
return NULL;
}
}
}
$cl = new myclass();
$cl->arr['a'] = 'a';
$out =& $cl->get('a');
echo $out; // a
$cl->arr['a'] = 'b';
echo $out; // a
$cl = new myclass();
$cl->arr['a'] = 'a';
$out =& $cl->get_by_ref('a');
echo $out; // a
$cl->arr['a'] = 'b';
echo $out; // b
?>