【问题标题】:Method declaration is compatible but PHP complains方法声明是兼容的,但 PHP 抱怨
【发布时间】:2012-10-19 08:52:51
【问题描述】:

所以我有这门课:

class JSObjectStorage extends \SplObjectStorage
{

    /**Adds a JavaScript object inside the storage, and optionally associate it to some data.*/    
    public function attach($javaScript, $data = null){}

    /**Removes the object from the storage.*/
    public function detach($javaScript){}

    /**Adds all objects-data pairs from a different JavaScriptBundle storage in the current storage.*/
    public function addAll(\SplObjectStorage $storage){}

    /**Removes objects contained in another storage from the current storage.*/
    public function removeAll(\SplObjectStorage $storage){}

    /**Removes all objects except for those contained in another storage from the current storage.*/
    public function removeAllExcept(\SplObjectStorage $storage){}

    /**Alias to JSObjectStorage::attach. */    
    public function offsetSet($javaScript, $data = null){}

    /**Alias to JSObjectStorage::detach*/
    public function offsetUnset($javaScript){}

    /**Returns the data associated with an object in the storage.*/
    public function offsetGet($javaScript){}

    /**This method calculates an identifier for the objects added to JSObjectStorage object.*/
    public function getHash($javaScript){}
}

这是 SplObjectStorage:

http://php.net/manual/en/class.splobjectstorage.php

如您所见,它们是相同的,但是当我实例化 JSObjectSTorage 时,出现以下错误:

严格标准:声明 MOWAFW\Core\Type\JavaScript\JSObjectStorage::addAll() 应该是 与 SplObjectStorage::addAll() 中的兼容 /Users/**/JSObjectStorage.php 第 175 行

这发生在 removeAll() 和 removeAllExcept() 上。

有什么想法吗?!


我正在使用:

PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 20 2012 22:55:53) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

【问题讨论】:

  • 您使用的是什么版本的 PHP?刚刚尝试使用 5.4.8,您的代码运行良好。
  • 您确定removeAll() 方法也不会发生这种情况吗?如果是这样,那么我会怀疑参数的类型提示可能会导致它 - 可能与您的 PHP 版本不兼容,但不确定。
  • @inhan 是的,就像我在问题中所说的那样,removeAll() 和 removeAllExcept() 也会发生这种情况。删除类型提示并不能解决问题。
  • 我一定错过了,抱歉。然后,显然它与类型提示有关。看起来像bug #40653,尽管版本不同。
  • @inhan 啊!该死的地狱!!!这是一个非常讨厌的错误。至少有一个解决方法,但即便如此......嗯,非常感谢你。做出回答,“绿色勾号”就是你的了。

标签: php splobjectstorage


【解决方案1】:

有人发布了一个名为 "Namespace interfaces not working due to type hinting issues" (Bug #40653) 的错误报告,尽管 PHP 版本不同(它显示为 v. ),但它看起来像您的情况。。 p>

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2023-03-31
    • 2010-10-21
    相关资源
    最近更新 更多