|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-02-01 23:11 UTC] dave at mudsite dot com
Description: ------------ --- From manual page: http://www.php.net/language.namespaces.dynamic --- When not using namespaces the following code works just fine Function loadClass ($class) { $this->obj = new $class(); } However, when attempting to implement namespaces: function loadClass ($class) { $this->obj = \classes\$class(); } Throws an "Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING". Which is kind of silly, since the corrected function looks like: function loadClass ($class) { $class = '\classes\\'.$class; $this->obj = new $class(); } Upon reading other bugs that query about using dynamic content in namespaces, I'm confused as to why the latter example above actually does work if namespaces are computed on compile time, when the class isn't known at compile time. Expected result: ---------------- I kindly request that you be able to use dynamic elements when using namespaces. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 21:00:01 2025 UTC |
I guess I should note, that the variable coming into this function would be something like: 'user' user.php-- <?php namespace classes; class user { }