Edit report at https://bugs.php.net/bug.php?id=53904&edit=1
ID: 53904 Updated by: s...@php.net Reported by: dave at mudsite dot com Summary: Use of dynamic class name in namespace construction -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Scripting Engine problem Operating System: Linux x86 PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. You can use __NAMESPACE__ for dynamically constructing namespaced names. Previous Comments: ------------------------------------------------------------------------ [2011-02-01 23:12:29] dave at mudsite dot com I guess I should note, that the variable coming into this function would be something like: 'user' user.php-- <?php namespace classes; class user { } ------------------------------------------------------------------------ [2011-02-01 23:11:00] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=53904&edit=1