note 112165 added to function.extract

From: Date: Mon, 13 May 2013 02:56:27 +0000
Subject: note 112165 added to function.extract
Groups: php.notes 
Request: Send a blank email to php-notes+get-194786@lists.php.net to get a copy of this message
It is possible to use this as a way to create public attributes for a class. <?php class Foo { public function __construct ($array) { extract($array, EXTR_REFS); foreach ($array as $key => $value) { $this->$key = $$key; // Do: $this->key = $key; if $key is not a string. } } } $array = array( 'valueOne' => 'Test Value 1', 'valueTwo' => 'Test Value 2', 'valueThree' => 'Test Value 3' ); $foo = new Foo($array); // Works echo $foo->valueOne; // Test Value 1 echo $foo->valueTwo; // Test Value 2 // Does not work! echo $foo::$valueOne; // Fatal error: Access to undeclared static property: Test::$valueOne ?> ---- Server IP: 64.71.164.2 Probable Submitter: 173.30.229.193 ---- Manual Page -- http://php.net/manual/en/function.extract.php Edit -- https://master.php.net/note/edit/112165 Del: integrated -- https://master.php.net/note/delete/112165/integrated Del: useless -- https://master.php.net/note/delete/112165/useless Del: bad code -- https://master.php.net/note/delete/112165/bad+code Del: spam -- https://master.php.net/note/delete/112165/spam Del: non-english -- https://master.php.net/note/delete/112165/non-english Del: in docs -- https://master.php.net/note/delete/112165/in+docs Del: other reasons-- https://master.php.net/note/delete/112165 Reject -- https://master.php.net/note/reject/112165 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194786) next »