note 71985 deleted from keyword.extends by bjori

From: Date: Tue, 24 Jul 2007 11:20:56 +0000
Subject: note 71985 deleted from keyword.extends by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128880@lists.php.net to get a copy of this message
Note Submitter: visus at portsonline dot net ---- I searched for a way to do something like this: <?php $foobar = "A"; class A { ... } class B extends $foobar { ... } ?> There is no way to get this working, but I found following workaround: activerecord.lib.php: <?php class ActiveRecord extends EXTENSION { function ActiveRecord() { print("foo"); } } ?> test.php: <?php $databaseSystem = "mysql"; class mysql { function show() { print("bar"); } } function includeExtendedClass($classFile, $extension) { $file = file_get_contents($classFile); eval(str_replace("EXTENSION", $extension, preg_replace("/<\?(php)?|\?>/", "", $file))); } includeExtendedClass("activerecord.lib.php", $databaseSystem); $instance = new ActiveRecord; $instance->show(); ?>

« previous php.notes (#128880) next »