OK, I went and looked at the code. It works as I expected (the reason the old-style constructor doesn't work is that the class name no longer matches the method name because of the namespace prefix), but for a period from 2008-2010 there was a workaround in place to de-namespace the classname before the check; that workaround was reverted in r297482.
I love how they handled the test:
--TEST--
- 063: Support for old-style constructors in namesapces
+ 063: Old-style constructors in namesapces (not supported!)
--FILE--
<?php
namespace Foo;
class Bar {
function Bar() {
echo "ok\n";
}
}
new Bar();
+ echo "ok\n";
--EXPECT--
ok
That may be so but this isn't a bug. If there was a language specification then we might be able to call it a bug. But PHP has no official language specification.
If there were a specification, we would be able to say whether the bug was in the specification or in the parser.
Since there is no specification, my only option is to to call it a parser bug. I certainly don't think it was intentional.
However we know it's written in C++ and is heavily influenced by it, so we can maybe look to C++ to see what's going on.
That might be a little misleading. PHP is written in C and the object system is much closer to Java than C++.
Traditionally the new operator allocates memory for the object and returns a reference to the uninstantiated object. Overload new in C++ to see this; you return a pointer to raw memory, not an object.
I think wvenable was talking about the new operator (which allocates, initializes and returns a new object); you're talking about what C++ calls operator new() (which controls only the first part).
Which is why with the way C++ evaluates expressions, you can't chain from new. But you can force evaluation after instantiation with parentheses, e.g. foo* x = (new foo())->bar();
The C++ equivalent of Java's new Foo().bar() wouldn't be new Foo()->bar() but Foo().bar(), which parses perfectly. After using new you own the pointer, so dropping it on the floor would be bad form.
I've been there. The machine said my laptop had explosives residue on it. It started beeping loudly and flashing "EXPLOSIVES" on its little screen.
The security people's response? Well, they cleared out the people behind me (to a blast radius of 20 feet or so), brought out The Form, filled it out, stamped it, and sent me on my way.
I wonder if this was before or after the actual game... (someone wrote a game where everything on screen is static, and the actual content was encoded in the relative motion of the pixels; my google-fu is weak today and I can't find it)
"We seem to have a compulsion these days to bury time capsules in order to give those people living in the next century or so some idea of what we are like. I have prepared one of my own. I have placed some rather large samples of dynamite, gunpowder, and nitroglycerin. My time capsule is set to go off in the year 3000. It will show them what we are really like."
For browsers that "silently" drop broken HTTPS resources from HTTP pages, so you can do this:
OK, I went and looked at the code. It works as I expected (the reason the old-style constructor doesn't work is that the class name no longer matches the method name because of the namespace prefix), but for a period from 2008-2010 there was a workaround in place to de-namespace the classname before the check; that workaround was reverted in r297482.
I love how they handled the test:
Oh wow, they actually removed one of the old language warts!
(granted, it happened only by accident, I assume; if you could somehow create a method named
namespace\MyClass, it would still work, right?)You should crosspost this to
/r/lolphp, we collect cases where the PHP interpreter fucks you over in non-intuitive ways.Good. Next corner case: put your app in /~myapp/ :-)
If your application is in /myapp/, see what happens to /myapp/myroute/bleh/myapp/foo/
If there were a specification, we would be able to say whether the bug was in the specification or in the parser.
Since there is no specification, my only option is to to call it a parser bug. I certainly don't think it was intentional.
That might be a little misleading. PHP is written in C and the object system is much closer to Java than C++.
I think wvenable was talking about the
newoperator (which allocates, initializes and returns a new object); you're talking about what C++ callsoperator new()(which controls only the first part).The C++ equivalent of Java's
new Foo().bar()wouldn't benew Foo()->bar()butFoo().bar(), which parses perfectly. After usingnewyou own the pointer, so dropping it on the floor would be bad form.Because of a (still unfixed?) parser bug
I don't think that's the right approach.
The turkey vulture.
Does "prove the bible wrong" or something similar sound ungrammatical to you as well?
Please explain.
I've been there. The machine said my laptop had explosives residue on it. It started beeping loudly and flashing "EXPLOSIVES" on its little screen.
The security people's response? Well, they cleared out the people behind me (to a blast radius of 20 feet or so), brought out The Form, filled it out, stamped it, and sent me on my way.
First part.
Thunderwear.
Public service announcement: SMBC has a red button.
I wonder if this was before or after the actual game... (someone wrote a game where everything on screen is static, and the actual content was encoded in the relative motion of the pixels; my google-fu is weak today and I can't find it)
EDIT: Not the game but a typical screenshot
… and this one
Are you sure? My Geek Sense™ and my (OSX Oxford) dictionary both tell me it should be singular.
Unnecessary Exposition Comics (from)
Also, what chiaolun said. Hopefully, you won't need to donate anything :)
Dude, this is bad mojo. You need to officially donate the profits.
"We seem to have a compulsion these days to bury time capsules in order to give those people living in the next century or so some idea of what we are like. I have prepared one of my own. I have placed some rather large samples of dynamite, gunpowder, and nitroglycerin. My time capsule is set to go off in the year 3000. It will show them what we are really like."
This guy, but he can't tell you why.
Holy crap, that's some bad babelfish right there.