php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61383 can't define type of var in class method
Submitted: 2012-03-14 06:45 UTC Modified: 2012-03-14 06:56 UTC
From: keryax at ya dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.0 OS: windows server 2003 R2
Private report: No CVE-ID: None
 [2012-03-14 06:45 UTC] keryax at ya dot ru
Description:
------------
I've got strange error:

Catchable fatal error: Argument 1 passed to omg::lol() must be an instance of integer, integer given

When I've replaced "integer" to "int", I've got:

Catchable fatal error: Argument 1 passed to omg::lol() must be an instance of int, integer given

Test script:
---------------
class omg{
	public static function lol(integer $A){
		return true;	
	}
}
echo omg::lol(123);

Expected result:
----------------
calling the method
--
captain obvious

Actual result:
--------------
Catchable fatal error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-14 06:56 UTC] rasmus@php.net
PHP does not have scalar type hints. 

   public static function lol(integer $A)

That says that you want $A to be an instance of Class integer. That's completely 
distinct from the scalar integer type.

Try this:

class integer { }

class omg{
	public static function lol(integer $A){
		return true;	
	}
}
echo omg::lol(new integer);
 [2012-03-14 06:56 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Dec 07 23:00:02 2025 UTC