uopz_implement

実行時にインターフェイスを実装させる

説明

bool uopz_implement(string $class, string $interface)

classinterface を実装させます。

パラメータ

class

interface

戻り値

成功した場合に true を、失敗した場合に false を返します。

エラー / 例外

PHP 7.4.0 以降では、 OPcache が有効になっており、 かつ class のエントリが変更不能な場合、 uopz_implements 関数は RuntimeException をスローするようになりました。

例1 uopz_implement の例

<?php
interface myInterface {}

class 
myClass {}

uopz_implement(myClass::class, myInterface::class);

var_dump(class_implements(myClass::class));
?>

上の例の出力は以下となります。

array(1) {
  ["myInterface"]=>
  string(11) "myInterface"
}