【问题标题】:Why are dynamic class methods specified with the double colon notation?为什么用双冒号表示动态类方法?
【发布时间】:2011-03-06 14:46:48
【问题描述】:

这让我很困惑:http://php.net/manual/en/dateinterval.format.php

public string DateInterval::format ( string $format )

该方法不是静态的,但它带有双冒号。这是什么原理?

【问题讨论】:

  • 这只是手册作者试图迷惑新手。

标签: php class methods static


【解决方案1】:

这只不过是 PHP 作者/开发人员编写由其类限定的方法名称的方式。它与方法的静态/动态性质无关。

您也会在 PHP 的错误中发现这种表示法。例如,

$o = new stdClass;
$o->method();

产生这个错误:

致命错误:调用未定义的方法stdClass::method()

【讨论】:

  • 至于为什么他们不能写像DateTime->format() 这样的东西,我不是团队中的一员,所以我不能说太多......
猜你喜欢
  • 2011-08-21
  • 2011-08-11
  • 2011-04-14
  • 1970-01-01
  • 2019-09-14
  • 2011-03-01
  • 2018-01-02
  • 2016-05-16
相关资源
最近更新 更多