php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54862 Type hinting for documentation
Submitted: 2011-05-19 14:17 UTC Modified: 2011-05-19 18:00 UTC
From: simon at systemparadox dot co dot uk Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: simon at systemparadox dot co dot uk
New email:
PHP Version: OS:

Further comment on this bug is unnecessary.

 

 [2011-05-19 14:17 UTC] simon at systemparadox dot co dot uk
Description:
------------
Since the dawn of time the PHP documentation has contained function declarations like this:

string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

But the PHP parser does not allow this syntax. Many people have been trying to get proper type hinting into PHP for some time now, and I appreciate some of the problems in doing so (although it really is needed ASAP).

However, as far as I'm concerned, a good 60% of the reason for wanting type hinting is for documentation purposes, and readability. Until the type hinting is implemented fully, please can we at least allow the PHP parser to accept the type hinting keywords for documentation purposes.

At the moment I'm on the verge of writing an extended PHP language with type hinting that compiles to PHP by removing the type keywords. That's completely insane, but the current situation leaves no choice.

Thanks.

Test script:
---------------
function int foo(bool bar, string baz) { }

Expected result:
----------------
The PHP parser should at least accept this syntax, even if it's not used yet.

Actual result:
--------------
Parse error.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-19 18:00 UTC] rasmus@php.net
-Status: Open +Status: Bogus -Block user comment: No +Block user comment: Yes
 [2011-05-19 18:00 UTC] rasmus@php.net
The issue is that scalar types are interchangeable in PHP out of necessity. The 
Web is not typed. Everything comes across the wire from the browser as a string. 
Once you start forcing string or integer in function calls you are pushing the 
type juggling to the caller instead of leaving it with the receiver where it 
belongs. Type hinting for non-scalar non-interchangeable types doesn't break 
thing which is why it is in.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 18:01:31 2024 UTC