|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-11-28 22:41 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 23:00:02 2025 UTC |
Description: ------------ Feature Request: The construct: class foo2 extends foo1{} will only accept a T_STRING for foo1 But what is highly desired is to also accept a T_VARIABLE. class $strFoo2 extends $strFoo1{} Should be a valid construct. This would enable some very powerful techniques, such as object encapsulation and psudo-nesting. Reproduce code: --------------- //Goal: To encapsulate a multiply subclassed object class foo1{ function foo1{echo "foo1\n";} } $MyClass = "foo1"; class foo2 extends $MyClass{ function CoolExtention1{echo "Cool Extension #1\n";} } $MyClass = "foo2"; class foo3 extends $MyClass{ function TotallyCoolExt{echo "Totally Cool Ext #2\n";} } $MyClass = "foo3"; ////////////// // // The program now sees an encapsulated class // without having to know anything in advance. // and without having to be modified when changes // are made to the object. $MyObj = new $MyClass; Expected result: ---------------- /******************* It's a question of being able to isolate the dependancies I don't want to hard-code the class names because I have multiple alternative extendors for the base class. It's basically a bunch of building blocks that I assemble as needed to create a custom class, giving me a common interface but with different functional implementations. I want the consuming program to see a single encapsulated object class. Aggrate does not do inheritance. PHP5 has Great!!! tools for working with objects and functions. But Encapsulation is one area it lacks and which could easily? be added by enabling the class definition to parse T_VARIABLEs and then using the trick above. This gives you the functional equivlent of nested classes as long as you manage your references carefully. I did manage to get this working using eval, but it's an ugly hack when dealing with a class of any complexity. \$everywhere. I also have some concerns about what the eval approach may be doing to runtime performance versus what could be done at cachable compile time. ///////////////////////////////////////////////////////// Taking it to the next level...a trick nobody else can do? class $strfoo2 extends $MyClass{ function {$strfoo2}{echo "Awesome $strfoo2 class!\n";} } *******************/ Actual result: -------------- Parse error: unexpected T_VARIABLE, expecting T_STRING