php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66476 Test if abstract conditions are OK
Submitted: 2014-01-13 14:57 UTC Modified: 2014-01-13 16:19 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dev at toine dot pro Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.24 OS: Debian
Private report: No CVE-ID: None
 [2014-01-13 14:57 UTC] dev at toine dot pro
Description:
------------
Hi!

Currently when we extends on abstract class we cannot test if all conditions are met before instantiate the class.

This is not usefull, can you improve ReflectionClass::isInstantiable or create new method for this feature?

Test script:
---------------
class classTest extends abstractTest {
  // Missing methodTest
}

abstract class abstractTest {
  abstract public function methodTest();
}

Expected result:
----------------
class classTest extends abstractTest {
  // Missing methodTest
}

abstract class abstractTest {
  abstract public function methodTest();
}

$reflectionClass = new ReflectionClass('calssTest');
if($reflectionClass->IsInstantiable()) {
  // OK
} else {
  // Cutom error
}

Actual result:
--------------
Fatal error: Class classTest contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (abstractTest::methodTest)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-13 16:19 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2014-01-13 16:19 UTC] nikic@php.net
You *can't* create a class that does not satisfy all the conditions (that's the point of having conditions). If you want to do that you must mark the class abstract as well. In that case you can use isAbstract() to check whether it is instantiable.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 01:00:01 2026 UTC