php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77966 Cannot alias a method named "namespace"
Submitted: 2019-05-04 01:42 UTC Modified: 2019-05-07 15:23 UTC
From: mattacosta at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.3.5 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: mattacosta at gmail dot com
New email:
PHP Version: OS:

 

 [2019-05-04 01:42 UTC] mattacosta at gmail dot com
Description:
------------
Methods may use semi-reserved keywords, however it is not possible to alias a method named "namespace". According to the error, the alias statement somehow becomes equivalent to 'as as bar'.

Test script:
---------------
<?php

trait A {
    function namespace() {}
}

class C {
    use A {
        namespace as bar;
    }
}

Expected result:
----------------
No error. This should be no different than if the method were named 'foo' and then using 'foo as bar'.

Actual result:
--------------
Fatal error: An alias (bar) was defined for method as(), but this method does not exist in /in/DmNne on line 7

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-07 15:23 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2019-05-07 15:23 UTC] nikic@php.net
I think the problem here is that we'll only reduce T_NAMESPACE as a semi-reserved identifier after already fetching T_AS as the next lookahead token, at which point zend_lex_tstring() will use the contents of "as" rather than "namespace".
 [2020-06-05 17:11 UTC] nikic@php.net
The following pull request has been associated:

Patch Name: Fix bug #77966: Cannot alias a method named "namespace"
On GitHub:  https://github.com/php/php-src/pull/5668
Patch:      https://github.com/php/php-src/pull/5668.patch
 [2020-06-08 10:59 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b03cafd19c01db57b89727ce77cc89a7d816077c
Log: Fix bug #77966: Cannot alias a method named &quot;namespace&quot;
 [2020-06-08 10:59 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Apr 22 21:01:23 2021 UTC