|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-23 17:03 UTC] nlhowell at cableone dot net
Description:
------------
If you define an abstract class, ReflectionClass says it is not abstract and is instantiable.
Reproduce code:
---------------
<?php
abstract class X { private $y = 5; }
$class = new ReflectionClass("X");
print "Class X:<br>";
print "Abstract: ";
var_dump($class->isAbstract());
print "<br>Instantiable: ";
var_dump($class->isInstantiable());
print "<br><br>Reflection Export:<pre>";
Reflection::Export($class);
print "</pre><br>var_dump of X:<pre>";
var_dump(new X());
print "</pre><br>";
?>
Expected result:
----------------
Class X:<br>Abstract: bool(true)
<br>Instantiable: bool(false)
<br><br>Reflection Export:<pre>Class [ <user> abstract class X ] {
@@ c:\Inetpub\wwwroot\php5lib2\test.php5 4-4
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [1] {
Property [ <default> private $y ]
}
- Methods [0] {
}
}
</pre><br>var_dump of X:<pre><br />
<b>Fatal error</b>: Cannot instantiate abstract class X in <b>c:\Inetpub\wwwroot\php5lib2\test.php5</b> on line <b>15</b><br />
Actual result:
--------------
Class X:<br>Abstract: bool(false)
<br>Instantiable: bool(true)
<br><br>Reflection Export:<pre>Class [ <user> abstract class X ] {
@@ c:\Inetpub\wwwroot\php5lib2\test.php5 4-4
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [1] {
Property [ <default> private $y ]
}
- Methods [0] {
}
}
</pre><br>var_dump of X:<pre><br />
<b>Fatal error</b>: Cannot instantiate abstract class X in <b>c:\Inetpub\wwwroot\php5lib2\test.php5</b> on line <b>15</b><br />
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 11:00:02 2025 UTC |
Doesnt seem to be fixed. --- abstract class Expression { function isConstant() { return FALSE; } } abstract class ConstantExpression extends Expression { function isConstant() { return TRUE; } } abstract class NumberExpression extends ConstantExpression { protected $number; function __construct($number) { $this->number = $number; } function getValue() { return $this->number; } } class IntegerExpression extends NumberExpression { } class RealExpression extends NumberExpression { } echo '<table>'; foreach(get_declared_classes() as $className) { $class = new ReflectionClass($className); if ($class->isUserDefined()) { echo '<tr><td>'.htmlspecialchars($class->getName()).'</td><td>'.($class->isAbstract() ? 'YES' : 'NO').'</td></tr>'; } unset($class); } echo '</table>'; -- Reports everything as not abstract. Used latest win32 snapshot available, PHP Version 5.0.1-dev System Windows NT WIN2KS 5.0 build 2195 Build Date Jul 20 2004 16:21:09