[英]PHP Fatal error: Declaration of ... must be compatible with
I can´t find the problem.我找不到问题。 This code works over years, but after reset the server this fatal-error was displayed.
此代码工作多年,但在重置服务器后显示此致命错误。 Maybe you can help me.
也许你可以帮助我。 Thank you
谢谢
PHP Fatal error: Declaration of styBoxLoadEventArgs::__construct() must be compatible with EventArgs::__construct() in .../modules/sty/events/styBoxLoadEventArgs.php on line 4
PHP 致命错误:第 4 行的 .../modules/sty/events/styBoxLoadEventArgs.php 中的 styBoxLoadEventArgs::__construct() 声明必须与 EventArgs::__construct() 兼容
the code is:代码是:
<?php
class styBoxLoadEventArgs extends EventArgs
{
public $hide = false;
public $box;
public function __construct($box)
{
$this->box = $box;
}
}
?>
here is the code of the EventArgs这是 EventArgs 的代码
?php
/**
* EventArgs
*/
abstract class EventArgs
{
public $sender, $senderClass, $senderObject, $event;
protected $items;
/**
* Creates new EventArgs object
*/
abstract public function __construct();
/**
* Returns specified item
*
* @param string item-name
* @return mixed
*/
public function __get($_name)
{
if(!array_key_exists($_name, $this->items))
{
throw new BasicException("Item '" . $_name . "' not found");
}
return $this->items[$_name];
}
/**
* Sets specified item
*
* @param string item-name
* @param mixed value
*/
public function __set($_name, $_value)
{
if(!array_key_exists($_name, $this->items))
{
throw new BasicException("Item '" . $_name . "' not found");
}
$this->items[$_name] = $_value;
}
public function &GetByRef($_key)
{
if(!array_key_exists($_key, $this->items))
{
throw new BasicException("Item '" . $_key . "' not found");
}
return $this->items[$_key];
}
}
When a child redeclares a function that a parent has defined, you have to keep the same hinting/data types for the function. 当子项重新声明由父项定义的函数时,必须为该函数保留相同的提示/数据类型。 So let's say
EventArgs
asks for a specific data object in its constructor (or in PHP7 uses strict type hints). 因此,假设
EventArgs
在其构造函数中要求一个特定的数据对象(或在PHP7中使用严格的类型提示)。 Your child must also specify that data type. 您的孩子还必须指定该数据类型。 Here's an example (made one up)
这是一个例子(拼凑而成)
class EventArgs
{
public function __construct(Array $box)
{
$this->box = $box;
}
}
In this case, your child constructor must also ask for an Array
. 在这种情况下,您的子构造函数还必须请求
Array
。 There's some elaborate reasons for this 这有一些详尽的原因
@schnittstelle, I think we are both working on the same software problem. @schnittstelle,我认为我们两个人都在解决同一个软件问题。 My ..date software no longer go after the switch to PHP 5.6.
切换到PHP 5.6后,我的..date软件不再运行。 Thanks to this page, I am now one step further but put again firmly.
多亏了此页面,我现在又前进了一步,但再次坚定地提出。 Did you come on and runs it with you?
你来和你一起跑吗? Unfortunately I am PHP layman, looking me through here, but would need but help.
不幸的是,我是PHP外行,在这里寻找我,但是需要帮助。 Have also been posted in the forum of ..date.de, but received no response.
也已发布在..date.de论坛中,但未收到任何回复。 Howl.
嗥。 LG Angelika
LG安吉莉卡
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.