php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28094 class type hints ambiguity
Submitted: 2004-04-21 16:40 UTC Modified: 2004-08-03 11:17 UTC
From: steve at przepiora dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0RC1 OS: windows xp
Private report: No CVE-ID: None
 [2004-04-21 16:40 UTC] steve at przepiora dot org
Description:
------------
When using class type hints with a string a runtime error occurs. 

Reproduce code:
---------------
<?php
function foo(string $bar){
    echo $bar;
}

foo("baz");
?>

Expected result:
----------------
The printout of "baz"



Actual result:
--------------
Fatal error: Argument 1 must be an object of class string in c:\program files\apache group\Apache\htdocs\index.php on line 2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-21 16:41 UTC] amt@php.net
Class type hints do not work with non-classes, like 
strings, integers, and arrays.

The error message is telling you it's expecting a class 
named "string." :)
 [2004-08-03 11:07 UTC] suky0001 at hotmail dot com
Er... Could this be implemented in a future release, please? (I'm a C++ programmer and variables with no types make me ill :P !!!)

Note that the page http://fr.php.net/zend-engine-2.php shows an Exception class that has this "problem":

class Exception {
   function __construct(string $message=NULL, int code=0) {...}

The page should corrected (or the feature should be implemented to match the page!!!)

Thanks!
 [2004-08-03 11:17 UTC] derick@php.net
The only possible thing we will add is "array" and "resource" as type hints, but never "String" "int"  or "float", as PHP is a loosly typed language unlike Jabba.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC