Edit report at http://bugs.php.net/bug.php?id=53904&edit=1

 ID:                 53904
 Comment by:         dave at mudsite dot com
 Reported by:        dave at mudsite dot com
 Summary:            Use of dynamic class name in namespace construction
 Status:             Open
 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:

I guess I should note, that the variable coming into this function would
be 

something like:



'user'



user.php--

<?php

namespace classes;



class user {



}


Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/bug.php?id=53904&edit=1

Reply via email to