ReflectionClass::isAbstract

(PHP 5)

ReflectionClass::isAbstractChecks if class is abstract

Description

public bool ReflectionClass::isAbstract ( void )

Checks if the class is abstract.

Parameters

This function has no parameters.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 ReflectionClass::isAbstract() example

<?php
class          TestClass { }
abstract class 
TestAbstractClass { }

$testClass     = new ReflectionClass('TestClass');
$abstractClass = new ReflectionClass('TestAbstractClass');

var_dump($testClass->isAbstract());
var_dump($abstractClass->isAbstract());
?>

The above example will output:

bool(false)
bool(true)

See Also

Коментарии

For interfaces and traits :

<?php
interface TestInterface { }
trait     
TestTrait { }

$interfaceClass = new ReflectionClass('TestInterface');
$traitClass     = new ReflectionClass('TestTrait');

var_dump($interfaceClass->isAbstract());
var_dump($traitClass->isAbstract());
?>

Using PHP versions 5.4- to 5.6, the above example will output:

bool(false)
bool(true)

Using PHP versions 7.0+, the above example will output:

bool(false)
bool(false)
2016-10-10 15:06:36
http://php5.kiev.ua/manual/ru/reflectionclass.isabstract.html
For traits:
- ReflectionClass::isAbstract returns true if the trait contains at least one un-implemented abstract method, including those declared into used traits.
- ReflectionClass::isAbstract returns false if all methods are implemented.

<?php
trait TI { public function has() {} }
var_dump((new ReflectionClass(TI::class))->isAbstract());

trait 
TT { abstract public function has(); }
trait 
{ use TT; }
var_dump((new ReflectionClass(T::class))->isAbstract());
?>
Will output:
bool(false)
bool(true)

For interfaces:
- ReflectionClass::isAbstract returns true if the interface contains at least one method, including into its extended interfaces.
- ReflectionClass::isAbstract returns false if the interface contains no method.

<?php
interface AI {}
var_dump((new ReflectionClass(AI::class))->isAbstract());

interface 
II { public function has(); }
interface 
extends II {}
var_dump((new ReflectionClass(I::class))->isAbstract());
?>
Will output:
bool(false)
bool(true)

For classes:
- Reflection::isAbstract returns true if the class is marked as abstract, no matter if it contains abstract methods or not.
2023-09-15 16:06:43
http://php5.kiev.ua/manual/ru/reflectionclass.isabstract.html

    Поддержать сайт на родительском проекте КГБ