When I create a standard class I mostly do:
$test = null;
$test->id = 1;
$test->name = 'name';
However in strict-mode I get an error.
So obviously the correct way of doing it is:
$test = new stdClass();
$test->id = 1;
$test->name = 'name';
So I am wondering:
Is it a big no-no to do: $test = null;
to do what I want?
What do we gain by conforming to the strict standards? Does it make sure code will keep on working in future versions? Will it be better backwards compatible? Is it just a matter of best practice? Something else?
EDIT typo
Is it a big no-no to do: $test = null; to do what I want?
Yes.
It's allowed because PHP is loose, but turning on strict mode gives you the god's-honest truth.
What do we gain by conforming to the strict standards? Does it make sure code will keep on working in future versions? Will it be better backwards compatible? Is it just a matter of best practice?
Yes.
Something else?
It's right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With