php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80497 Incorrect example #11 for ::class on OOP The Basics page
Submitted: 2020-12-09 06:04 UTC Modified: 2020-12-09 10:45 UTC
From: iamvar at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Class/Object related
PHP Version: Irrelevant OS:
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: iamvar at gmail dot com
New email:
PHP Version: OS:

 

 [2020-12-09 06:04 UTC] iamvar at gmail dot com
Description:
------------
On the https://www.php.net/manual/en/language.oop5.basic.php
There is a typo
It said that
print Some\Class\DoesNot\Exist::class;

will print Some\Class\Does\Not\Exist

But it will not, there are 2 problems:
Word Class in the namespace, missing slash for print statement DoesNot\Exist instead of Does\Not\Exist 

Test script:
---------------
print Some\Class\DoesNot\Exist::class;

Expected result:
----------------
print Does\Not\Exist::class;

will print Does\Not\Exist

Actual result:
--------------
Parse error:  syntax error, unexpected 'Class' (T_CLASS), expecting identifier (T_STRING) in php shell code on line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-09 06:14 UTC] requinix@php.net
-Summary: Incorrect example on OOP The Basics page +Summary: Incorrect example #11 for ::class on OOP The Basics page -Status: Open +Status: Verified -Package: Documentation problem +Package: Class/Object related
 [2020-12-09 06:14 UTC] requinix@php.net
> Word Class in the namespace,
As of PHP 8, using "Class" is okay because the namespace name is considered as a whole. https://3v4l.org/AEJP5

A revised example avoiding that issue and fixing the backslash would be

<?php
print Does\Not\Exist::class;
?>
 [2020-12-09 10:45 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-12-09 10:49 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=351963
Log: Fix #80497: Incorrect example #11 for ::class on OOP The Basics page
 [2020-12-09 10:50 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=4528db2d91279a8f120bacfd84e48f7e2281d923
Log: Fix #80497: Incorrect example #11 for ::class on OOP The Basics page
 [2020-12-09 10:50 UTC] phpdocbot@php.net
-Status: Verified +Status: Closed
 [2020-12-09 13:18 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=351971
Log: Fix #80497: Incorrect example #11 for ::class on OOP The Basics page
 [2020-12-09 13:20 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=23aa2c57d9b1ec4bfca77ab819863c45c9519124
Log: Fix #80497: Incorrect example #11 for ::class on OOP The Basics page
 [2020-12-30 11:58 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=08d533d600d19ad7c53bf61fd3033f2f140cf6f0
Log: Fix #80497: Incorrect example #11 for ::class on OOP The Basics page
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 03:01:29 2024 UTC