代码之家  ›  专栏  ›  技术社区  ›  Keith Palmer Jr.

在PHP5.x中,如何在运行时检测类是否是抽象的?

  •  22
  • Keith Palmer Jr.  · 技术社区  · 17 年前

    3 回复  |  直到 17 年前
        1
  •  36
  •   benizi vartec    15 年前

    使用反射。 ReflectionClass ->isAbstract()

    $class = new ReflectionClass('NameOfTheClass');
    $abstract = $class->isAbstract();
    
        2
  •  4
  •   jonstjohn    17 年前

    您可以使用 Reflection

        3
  •  4
  •   MrHus    17 年前
    <?php 
    
    abstract class Picasso
    {
        public function __construct()
        {
    
        }
    } 
    
    $class = new ReflectionClass('Picasso');
    
    if($class->isAbstract())
    {
        echo "Im abstract";
    }
    else
    {
        echo "Im not abstract";
    }
    
    ?>
    

    请参阅手册:www.php.net/oop5.reflection

        4
  •  -1
  •   Seb    17 年前
    推荐文章