Hi all,
I thought people might be amused to hear that, almost exactly 8 years
after it was proposed, this very reasonable decision caused a lot of
head-scratching yesterday:
From: Stanislav Malyshev <stas () zend ! com>
Date: 2010-04-03 1:17:44
So, I think we've got consensus about not having class-named ctors in
namespaced classes in trunk, and unless I hear some screams I'll commit
the patch early next week.What about the 5.3? (BTW, I don't see any difference between 5.3.0 and
anything later, could anybody point it to me?)
We could:
- Kill the class-named ctors for NS in 5.3 (some BC break, though I
have hard time believing anybody used it so far, but who knows)- Kill the warning and just ignore the other one if __ctor is there.
- Leave everything as-is.
While migrating an application off a horrifyingly old server, my friend
(who shall remain anonymous to protect the innocent) could not
understand why a private property of a class, initialised in the
constructor, was null when the code ran on the new server. It turns out
that the code in question looked like this:
namespace Foo\Bar;
class Baz {
public function baz() {
// initialisation here
}
}
This code runs correctly only on PHP versions from 5.3.0 to 5.3.2
inclusive, because in 5.3.3, Stas's patch mentioned above landed, and
the method is no longer detected as a constructor. It just so happens
that 5.3.2 was the version bundled with Ubuntu 10.04, and somehow the
code remained untested on any other version in all this time.
Out of curiosity, I tracked down why this was changed, and found this
thread. [https://marc.info/?l=php-internals&m=127014823111792] The
awkwardness of allowing both constructor styles was only discovered as
people started to move PEAR-style class names to namespaced ones, so
tweaking it in 5.3.3 made perfect sense. But, as Stas said in the
message quoted above, who knows what features people will take advantage
of, documented or otherwise!
Regards,
--
Rowan Collins
[IMSoP]