note 51313 deleted from function.eval by peehaa

From: Date: Mon, 09 Dec 2013 12:01:13 +0000
Subject: note 51313 deleted from function.eval by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197878@lists.php.net to get a copy of this message
Note Submitter: Ben Grabkowitz ---- The eval function becomes incredibly useful when dealing with static class members and variables. For instance: Lets say you have 3 classes; Foo, BarA and BarB, where BarA and BarB are children of Foo. Now lets also say that both BarA and BarB contain a static member function called getDataSource(). To call getDataSource() you would have to use the syntax: <?php BarA::getDataSource(); BarB::getDataSource(); ?> But lets say you need to access getDataSource() from inside class Foo during an instance of either BarA or BarB. You can use eval to do something like this: <?php eval('$dataSource=' . get_class($this) . '::getDataSource();'); ?>

« previous php.notes (#197878) next »