note 79460 added to language.variables.variable

From: Date: Wed, 28 Nov 2007 14:59:23 +0000
Subject: note 79460 added to language.variables.variable
Groups: php.notes 
Request: Send a blank email to php-notes+get-132634@lists.php.net to get a copy of this message
This example may help to overcome the limitation on $this. Populate automatically fields of an object form a $_GET variable. <?php class pp{ var $prop1=1,$prop2=2,$prop3=array(3,4,5); function fun1(){ $vars=get_class_vars('pp'); while(list($var,$value)=each($vars)){ $ref=& $this->$var; $ref=$_GET[$var]; } // while var_dump($this); } } $_GET['prop1']="uno"; $_GET['prop2']="dos"; $_GET['prop3']=array('tres','cuatro','cinco','seis'); $p=new pp(); $p->fun1(); ?> output is ... object(pp)#1 (3) { ["prop1"]=> &string(3) "uno" ["prop2"]=> &string(3) "dos" ["prop3"]=> &array(4) { [0]=> string(4) "tres" [1]=> string(6) "cuatro" [2]=> string(5) "cinco" [3]=> string(4) "seis" } } ---- Server IP: 80.64.47.13 Probable Submitter: 87.220.46.81 ---- Manual Page -- http://www.php.net/manual/en/language.variables.variable.php Edit -- https://master.php.net/note/edit/79460 Del: integrated -- https://master.php.net/note/delete/79460/integrated Del: useless -- https://master.php.net/note/delete/79460/useless Del: bad code -- https://master.php.net/note/delete/79460/bad+code Del: spam -- https://master.php.net/note/delete/79460/spam Del: non-english -- https://master.php.net/note/delete/79460/non-english Del: in docs -- https://master.php.net/note/delete/79460/in+docs Del: other reasons-- https://master.php.net/note/delete/79460 Reject -- https://master.php.net/note/reject/79460 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132634) next »