当我创建一个标准类时,我主要这样做:
$test = null;
$test->id = 1;
$test->name = 'name';
但是在严格模式下我得到一个错误。
显然正确的做法是:
$test = new stdClass();
$test->id = 1;
$test->name = 'name';
所以我想知道:
这是一个很大的禁忌吗:$test = null;
做我想做的事?
遵守严格的标准对我们有什么好处?它是否确保代码在未来的版本中继续工作?它会更好地向后兼容吗?这只是最佳实践的问题吗?还有别的吗?
编辑 打字错误
最佳答案
Is it a big no-no to do: $test = null; to do what I want?
是的。
这是允许的,因为 PHP 是松散的,但打开严格模式会给你一个上帝诚实的真理。
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?
正确。
关于PHP 严格标准 : is this bad?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781285/