note 58723 added to keyword.paamayim-nekudotayim

From: Date: Mon, 14 Nov 2005 05:40:12 +0000
Subject: note 58723 added to keyword.paamayim-nekudotayim
Groups: php.notes 
Request: Send a blank email to php-notes+get-98527@lists.php.net to get a copy of this message
'emulating' class variables in php4... peter at textstore dot c() dot il put me on the right track... I came up with the following and then before posting this realized that peterjoel.com has already posted almost the exact same thing... anyways, this is a little simpler and only involves one function instead of a getter/setter pair... class myClass { function &myVar($arg = NULL) { static $myClassVar; if (!is_null($arg)) { $myClassVar = $arg; } return($myClassVar); } } // Setting the 'class' var... myClass::myVar($myNewClassVar); // Getting the 'class' var... $classVarRef = &myClass::myVar(); This should let you set up 'class' vars that will hold anything you can reference... with a little creative array usage, you could modify this to allow any number of class vars without having to write the same above function for each one... hope someone finds it useful... ---- Manual Page -- http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58723 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58723&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58723&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98527) next »