PHP 严格标准 : is this bad?

标签 php stdclass

当我创建一个标准类时,我主要这样做:

$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/

相关文章:

php - 使用 preg_replace 命名反向引用

php - 我应该如何将这些表加入MySQL?

php - 类 stdClass 的对象无法转换为字符串

Laravel:如何将对象 stdclass 传递到我的 View 并调用它以及传递简单数组的区别?

php - yii 通过检查两个条件从表中获取结果

php - mysql中的longblob和longtext有什么区别?

php - 按时间倒序从多个表中打印唯一值

php - 在 PHP 中创建我自己的类时,我应该扩展 stdClass 吗?

php - 带有 <stdClass> 标签的 SOAP 请求