note 71985 added to keyword.extends

From: Date: Wed, 27 Dec 2006 21:43:38 +0000
Subject: note 71985 added to keyword.extends
Groups: php.notes 
Request: Send a blank email to php-notes+get-120965@lists.php.net to get a copy of this message
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(); ?> ---- Server IP: 217.13.201.10 Probable Submitter: 84.62.156.124 ---- Manual Page -- http://www.php.net/manual/en/keyword.extends.php Edit -- https://master.php.net/note/edit/71985 Del: integrated -- https://master.php.net/note/delete/71985/integrated Del: useless -- https://master.php.net/note/delete/71985/useless Del: bad code -- https://master.php.net/note/delete/71985/bad+code Del: spam -- https://master.php.net/note/delete/71985/spam Del: non-english -- https://master.php.net/note/delete/71985/non-english Del: in docs -- https://master.php.net/note/delete/71985/in+docs Del: other reasons-- https://master.php.net/note/delete/71985 Reject -- https://master.php.net/note/reject/71985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120965) next »