note 81506 added to language.variables.scope
| From: | Anonymous at osu1 dot php dot net | Date: | Sat, 01 Mar 2008 19:10:08 +0000 |
| Subject: | note 81506 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136643@lists.php.net to get a copy of this message | ||
I was pondering a little something regarding caching classes within a function in order to prevent
the need to initiate them multiple times and not clutter the caching function's class
properties with more values.
I came here because I remembered something about references being lost. So I made a test to see if I
could pull what I wanted to off anyway. Here's and example of how to get around the references
lost issue. I hope it is helpful to someone else!
<?php
class test1{}
class test2{}
class test3{}
function cache( $class )
{
static $loaders = array();
$loaders[ $class ] = new $class();
var_dump( $loaders );
}
print '<pre>';
cache( 'test1' );
cache( 'test2' );
cache( 'test3' );
?>
----
Server IP: 209.41.74.194
Probable Submitter: 76.22.73.161
----
Manual Page -- http://www.php.net/manual/en/language.variables.scope.php
Edit -- https://master.php.net/note/edit/81506
Del: integrated -- https://master.php.net/note/delete/81506/integrated
Del: useless -- https://master.php.net/note/delete/81506/useless
Del: bad code -- https://master.php.net/note/delete/81506/bad+code
Del: spam -- https://master.php.net/note/delete/81506/spam
Del: non-english -- https://master.php.net/note/delete/81506/non-english
Del: in docs -- https://master.php.net/note/delete/81506/in+docs
Del: other reasons-- https://master.php.net/note/delete/81506
Reject -- https://master.php.net/note/reject/81506
Search -- https://master.php.net/manage/user-notes.php