<?php
class Hoge {
private $val = 1;
public function getVal()
{
return $this->val;
}
}
trait MyTrait {
public function cry()
{
echo "nya";
}
}
function check($class_name) {
echo "================ ", $class_name, "\n";
$h = new \ReflectionClass($class_name);
echo "abstract? ", $h->isAbstract() ? "true" : "false" , "\n";
echo "trait? ", $h->isTrait() ? "true" : "false" , "\n";
echo "interface? ", $h->isInterface() ? "true" : "false" , "\n";
echo "実体化可能? ", $h->isInstantiable() ? "true" : "false" , "\n";
}
check("Hoge");
check("MyTrait");
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- ================ Hoge
abstract? false
trait? false
interface? false
実体化可能? true
================ MyTrait
abstract? false
trait? true
interface? false
実体化可能? false
- Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
- ================ Hoge
abstract? false
trait? false
interface? false
実体化可能? true
================ MyTrait
abstract? true
trait? true
interface? false
実体化可能? false
preferences:
254.4 ms | 402 KiB | 330 Q