note 81506 deleted from language.variables.scope by crell

From: Date: Thu, 31 Mar 2022 19:36:49 +0000
Subject: note 81506 deleted from language.variables.scope by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217924@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- 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' ); ?>

« previous php.notes (#217924) next »