note 82832 added to control-structures.alternative-syntax

From: Date: Mon, 28 Apr 2008 15:21:31 +0000
Subject: note 82832 added to control-structures.alternative-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-138869@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 212.202.128.183 ---- Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php Edit -- https://master.php.net/note/edit/82832 Del: integrated -- https://master.php.net/note/delete/82832/integrated Del: useless -- https://master.php.net/note/delete/82832/useless Del: bad code -- https://master.php.net/note/delete/82832/bad+code Del: spam -- https://master.php.net/note/delete/82832/spam Del: non-english -- https://master.php.net/note/delete/82832/non-english Del: in docs -- https://master.php.net/note/delete/82832/in+docs Del: other reasons-- https://master.php.net/note/delete/82832 Reject -- https://master.php.net/note/reject/82832 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138869) next »