php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79942 b/c break: new\class now fails
Submitted: 2020-08-07 11:15 UTC Modified: 2020-08-10 09:26 UTC
From: sjon@php.net Assigned: sjon (profile)
Status: Closed Package: Class/Object related
PHP Version: 8.0.0beta1 OS: archLinux
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: sjon@php.net
New email:
PHP Version: OS:

 

 [2020-08-07 11:15 UTC] sjon@php.net
Description:
------------
It's no longer to create an object from a specific namespace without a trailing space after the 'new' keyword. This change is not documented as b/c incompatible change in the NEWS or UPGRADING file. Somewhat inconsistently, `new$x` still works: https://3v4l.org/JSAFD


originally found as https://3v4l.org/ZMgiM



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

class x {}
new\x;

Actual result:
--------------
Fatal error: Uncaught Error: Undefined constant "new\x" in /in/KsknY:4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-07 11:51 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2020-08-07 11:51 UTC] cmb@php.net
That behavioral change is due to "RFC: Treat namespaced names as
single token"[1]; new\x is now a single token (same for some other
operators, e.g. instanceof).  That needs to be documented.

> Somewhat inconsistently, `new$x` still works […]

TIL, but actually not really surprising, since the scanner
"automatically" sees two tokens here.

[1] <https://wiki.php.net/rfc/namespaced_names_as_token>
 [2020-08-10 09:20 UTC] nikic@php.net
I have added a mention of this case to the UPGRADING note: https://github.com/php/php-src/commit/e81ad4089e7435bec8dc075089e9c47851b8ddb7
 [2020-08-10 09:26 UTC] sjon@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: sjon
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC