php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28895 ReflectionClass::isAbstract always returns false
Submitted: 2004-06-23 17:03 UTC Modified: 2004-07-20 20:32 UTC
From: nlhowell at cableone dot net Assigned: helly (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.0.0 OS: *
Private report: No CVE-ID: None
 [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 />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-23 17:05 UTC] nlhowell at cableone dot net
Note that the first two lines are the important ones in the expected and actual results.
 [2004-07-04 18:06 UTC] nlhowell at cableone dot net
Latest CVS (200407041430) has this bug listed as fixed.
 [2004-07-20 19:45 UTC] Jared dot Williams1 at ntworld dot com
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
 [2004-07-20 20:20 UTC] helly@php.net
Unfortunatley this wasn't fixed in 5 really.
 [2004-07-20 20:32 UTC] helly@php.net
Should be fixed now (obviously we need a testsuit for Reflection API any volunteers?)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC