Reputation: 3606
Some PHP built-in classes use the old naming scheme for their constructor (I.E. their class name). SoapVar
's constructor for example is Soapvar::SoapVar()
. Now I'm trying to extend that class and override its constructor. I have to use the class name to do that, the usual __constructor()
doesn't work.
Non-namespaced, using __constructor()
:
class SomeClass extends SoapVar {
public function __constructor() {
print "Trying to override parent's constructor.\n";
}
}
$class = new SomeClass(); /* Not working */
Non-namespaced, using class name as constructor:
class SomeClass extends SoapVar {
public function SomeClass() {
print "Trying to override parent's constructor.\n";
}
}
$class = new SomeClass(); /* Working */
Now I need to use a namespaced class. The only problem is this: As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. So this:
namespace Example\Namespace;
class SomeClass extends \SoapVar {
public function SomeClass() {
print "Trying to override parent's constructor.\n";
}
}
$class = new SomeClass(); /* Not working */
doesn't work! Is there any way to solve this or am I forced to use the global namespace? Is there a bug report somewhere for this issue?
Upvotes: 0
Views: 179