gpt4 book ai didi

php - 从继承接口(interface)的类调用静态方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:58:10 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Referring to a static member of a subclass

请查看以下代码以了解我的问题。

<?php

Interface IDoesSomething
{
public static function returnSomething();
}

abstract class MiddleManClass implements IDoesSomething
{
public static function doSomething()
{
return 1337 * self::returnSomething();
}
}

class SomeClass extends MiddleManClass
{
public static function returnSomething()
{
return 999;
}
}

// and now, the vicious call
$foo = SomeClass::doSomething();

/**
* results in a
* PHP Fatal error: Cannot call abstract method IDoesSomething::returnSomething()
*/
?>

有没有办法强制抽象returnSomething(),同时保持从抽象“中间人”类中定义的函数调用函数的可能性?对我来说,这似乎是 PHP 的瓶颈。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com