php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35363 Type Hinting doesn't work with strings
Submitted: 2005-11-24 12:50 UTC Modified: 2005-11-24 13:26 UTC
From: mg at memedia dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2005-11-24 (snap) OS: Various
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mg at memedia dot de
New email:
PHP Version: OS:

 

 [2005-11-24 12:50 UTC] mg at memedia dot de
Description:
------------
See above. Maybe there are als osome other variable types that doesn't work. Actually I only see that Classes and Arrays work.

Anyway, llive could be easier if I wouldn't need to tell every function to check for incoming variable types ;)

Reproduce code:
---------------
class Tasty {
    function mustBeArray(Array $test) {
        echo "Tasty::mustBeArray\n";
        return true;
    }
    function mustBeString(String $str) {
        print("Tasty::mustBeString\n");    
    }
    function testType($type){
        print("Tasty::testType\n");
        print(gettype($type)."\n");
    }
}
$t = new Tasty();
$t->mustBeArray(Array(1,2));
$t->testType((String)'test'); 
$t->mustBeString((String)'test'); // doesn't work


Expected result:
----------------
OUTPUT:

Tasty::mustBeArray
Tasty::testType
string
Tasey::mustBeString

Actual result:
--------------
OUTPUT:

Tasty::mustBeArray
Tasty::testType
string
Fatal error: Argument 1 passed to Tasty::mustBeString() must be an object of class String

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-24 13:26 UTC] tony2001@php.net
No bug here.
Only arrays and classes can be used for typehinting.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 01 07:00:01 2025 UTC