note 93065 added to language.oop5.late-static-bindings

From: Date: Fri, 21 Aug 2009 13:34:40 +0000
Subject: note 93065 added to language.oop5.late-static-bindings
Groups: php.notes 
Request: Send a blank email to php-notes+get-159743@lists.php.net to get a copy of this message
PHP5.3 unavailable, yet in the need for 'static', I did the following. Any objections? Personally I hate using the the eval() statement... <?php class mother { function setStatic( $prop, $val ) { // After this, self:: refers to mother, yet next $class refers to... // $class = get_class( $this ); eval( "$class::\$$prop = \$$val;" ); } } class child extends mother { protected static $sProp; function writer( $value ) { parent::setStatic( 'sProp', $value ); } function reader() { return self::$sProp; } } $c = new child(); $c->writer( 3 ); echo $c->reader(); // 3 ?> ---- Server IP: 213.249.64.162 Probable Submitter: 81.204.254.12 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.late-static-bindings.php Edit -- https://master.php.net/note/edit/93065 Del: integrated -- https://master.php.net/note/delete/93065/integrated Del: useless -- https://master.php.net/note/delete/93065/useless Del: bad code -- https://master.php.net/note/delete/93065/bad+code Del: spam -- https://master.php.net/note/delete/93065/spam Del: non-english -- https://master.php.net/note/delete/93065/non-english Del: in docs -- https://master.php.net/note/delete/93065/in+docs Del: other reasons-- https://master.php.net/note/delete/93065 Reject -- https://master.php.net/note/reject/93065 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159743) next »