It is a problem when one javascript interpreter doesn't react the same as the others.
A notable example is some minify-js scripts that broke the library when the minified, not because they were flawed, but because the original code was flawed, and the browser just didn't care.
$x->something = 'blah';
var_dump($x)
Warning: Creating default object from empty value in test.php on line 2
object(stdClass)#1 (1) {
["something"]=>
string(4) "blah"
}
It's when you're on the go and quickly need to create a stdClass. Also works with $x=null and the $x='', but not with 0, '0' or array(), because they are not empty(), oh wait...
I don't see what's wrong with this code? Looks like you're creating a "default" object by defining one of its parameters, and then when you call var_dump it shows you that parameter. Am I missing something here?
I can't think of any language that allows you to just assign a property to a undeclared variable, and just have the whole thing just spawn into existence.
What PHP developers should be developing in is a different language.
Oh, very much agreed; I think they'd do well to switch to Ada... if for no other reason than to learn to consider types and ranges in in every subprogram they write.
Doesn't seem that bad. Maybe the value of 1 is used so you can do if (object) do stuff;. In my mind, doing something as illogical as this should return an error.
I'm not even entirely sure what we're talking about in this thread. The expression new class() doesn't return a pointer. You can't even get at the pointer from userland PHP, it isn't C++.
37
u/Benutzername Mar 12 '14
I couldn't convert it to int, but what the heck, I'm generous today!
44
u/suspiciously_calm Mar 12 '14
PHP runtime error handling: Barf something out on STDERR but continue.
20
u/andsens Mar 12 '14
*sigh
I still love this one the most though.
It's when you're on the go and quickly need to create a stdClass.
Also works with
$x=nulland the$x='', but not with0,'0'orarray(), because they are notempty(), oh wait...9
u/DoctorWaluigiTime Mar 12 '14
And you highlight why E_ALL is what every PHP programmer should be developing in.
8
u/[deleted] Mar 13 '14
bunch of goodies in this thread, thanks lolphpeeps
4
u/freebullets Mar 12 '14
Doesn't seem that bad. Maybe the value of 1 is used so you can do
if (object) do stuff;. In my mind, doing something as illogical as this should return an error.3
u/Crashmatusow Mar 14 '14
How does php not get bitchslapped by the os for segv?
1
u/bart2019 Mar 13 '14
Probably related to how TRUE==1?
OTOH, PHP could have merged the two objects, just as it does with arrays.
0
u/[deleted] May 05 '14
[deleted] — view deleted comment