Ok. I wanted to create a abject from at string in php. Normally you would do it like following:
$obj = new $string();
But this didn’t work. I used a lot of time trying to rewrite it, but nothing. The thing was, that it worked at some other point in my script, so there wasn’t any meaning in it not working.
Then it occurred to me, that i was using namespaces, and that might be the problem.
So first i tried:
$obj = __NAMESPACE__."\\".$string();
that didn’t work. It seams that php don’t handle strings before object creation in this matter, so it didn’t create the string before trying to create the object.
However, following solved my problem:
$str = __NAMESPACE__."\\".$str;
$obj = new $str();
The conclusion must be, that PHP don’t handle current namespace when creating objects from strings. That might be a candidate for a bugrepport?





























