note 51313 added to function.eval

From: Date: Sun, 27 Mar 2005 02:57:22 +0000
Subject: note 51313 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-87039@lists.php.net to get a copy of this message
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: 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: eval('$dataSource=' . get_class($this) . '::getDataSource();'); ---- Manual Page -- http://www.php.net/manual/en/function.eval.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51313 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51313&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51313&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51313&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51313&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51313&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51313&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87039) next »