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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
12 - 7 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Sat Apr 20 02:01:29 2024 UTC