-1

我有两节课。

我想检查一个类是否是另一个类的实例而不初始化它们中的任何一个。

使用该功能is_subclass_of和使用时,instanceOf您必须初始化子类。

<?php

$classPath = 'app/foo/bar';
$subClassPath = 'app/foo/foo'; // Inherits from $classPath

// This is what I want to do but doesn't work.
echo $subClassPath instanceOf $classPath;

// Works
echo (new $subClassPath()) instanceOf $classPath;
4

1 回答 1

0

我发现了问题。

is_subclass_of要求你的斜线走另一条路。

$classPath = 'app\foo\bar';
$subClassPath = 'app\foo\foo'; // Inherits from $classPath

// Works
echo is_subclass_of($subClassPath $classPath);
于 2018-10-29T21:41:48.653 回答