php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33902 Type hinting incorrect behavior
Submitted: 2005-07-28 13:33 UTC Modified: 2005-07-28 16:26 UTC
From: sveta at microbecal dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.4 OS: FreeBSD, WindowsXP
Private report: No CVE-ID: None
 [2005-07-28 13:33 UTC] sveta at microbecal dot com
Description:
------------
In my example type hinting in method foo() in child class is incompatible with same method in parent class. But it still working with E_STRICT.

Reproduce code:
---------------
error_reporting(E_ALL | E_STRICT);

class A {}

abstract class B {
	protected $bar;
	
	public function foo($bar) {
		$this->bar = $bar;
		echo "some\n";
		return $this;
	}
}

class C extends B
{
	public function foo(A $bar)
	{
		$this->bar = $bar;
		
		echo "not expected\n";
		return $this;
	}
}

$c = new C;
$c->foo(new A);


Expected result:
----------------
Fatal error: Declaration of C::foo() must be compatible with that of B::foo() 

Actual result:
--------------
not expected

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-28 16:26 UTC] sniper@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC