php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70184 New reserved words for Scalar Types need to be case sensitive
Submitted: 2015-08-02 14:15 UTC Modified: 2015-08-02 17:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: lauren at laurenblack dot co dot uk Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 7.0.0beta2 OS: CentOS 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lauren at laurenblack dot co dot uk
New email:
PHP Version: OS:

 

 [2015-08-02 14:15 UTC] lauren at laurenblack dot co dot uk
Description:
------------
For PHP 5.3+ we have built a java-like scalar type encapsulation library to provide scalar type hinting. We designed the library to provide the full gamut of context related manipulations that the Java type classes do, as well.

Basically, since the reserved words for the scalar types are case insensitive, our enpowered Float, Int, String, etc. classes aren't allowed, which would mean a full rewrite of our libraries.

int =/= Int
float =/= Float
string =/= String

Test script:
---------------
<?php
class Float
{
    public $value;

    public function __construct (float $float)
    {
        $this->value = $float;
    }
    
    public function multiply(float $float): Float
    {
        $val = (float) $this->value * $float;
	return new Float($val);
    }
}

$val1 = new Float(2.5);
echo $val1->multiply(3.2)->value;

Expected result:
----------------
Output: 8

Actual result:
--------------
Fatal error: Cannot use 'Float' as class name as it is reserved in /var/www/clients/client1/web1/web/test/test.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-02 17:20 UTC] bwoebi@php.net
-Status: Open +Status: Wont fix
 [2015-08-02 17:20 UTC] bwoebi@php.net
We know that issue, we already discussed it back then http://markmail.org/message/xooy74qsnvfmf6hd (and following mails) … but decided that it is the price to pay, sorry.

And the reason why it is case-insensitive is because every keyword is case-insensitive. Changing that would make it either very inconsistent or breaking other code.

Also, class names in general are case-insensitive too.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC