Doc #80497 [Opn->Ver]: Incorrect example #11 for ::class on OOP The Basics page

From: Date: Wed, 09 Dec 2020 06:14:47 +0000
Subject: Doc #80497 [Opn->Ver]: Incorrect example #11 for ::class on OOP The Basics page
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18219@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80497&edit=1

 ID:                 80497
 Updated by:         requinix@php.net
 Reported by:        iamvar at gmail dot com
-Summary:            Incorrect example on OOP The Basics page
+Summary:            Incorrect example #11 for ::class on OOP The Basics
                     page
-Status:             Open
+Status:             Verified
 Type:               Documentation Problem
-Package:            Documentation problem
+Package:            Class/Object related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

> 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;
?>


Previous Comments:
------------------------------------------------------------------------
[2020-12-09 06:04:01] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80497&edit=1


Thread (3 messages)

« previous php.doc.bugs (#18219) next »