Bug->Doc #71598 [Opn]: Whitespace at the start of a function name counts as part of the function name.

From: Date: Mon, 15 Feb 2016 13:16:47 +0000
Subject: Bug->Doc #71598 [Opn]: Whitespace at the start of a function name counts as part of the function name.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-13190@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71598&edit=1 ID: 71598 Updated by: requinix@php.net Reported by: lucas at lucassifoni dot info Summary: Whitespace at the start of a function name counts as part of the function name. Status: Open -Type: Bug +Type: Documentation Problem -Package: PHP Language Specification +Package: Scripting Engine problem Operating System: Debian 8 PHP Version: 7.0.3 Block user comment: N Private report: N New Comment: It then goes on to specify a regex: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* Given that files must be saved in an encoding, your zero-width non-breaking space was probably encoded using UTF-8, thus your function is named "\xEF\xBB\xBFfoo" - which is valid, though terribly inconvenient to write in actual code. Rather than try to make PHP Unicode aware, something which has proven to be difficult in the past, for now perhaps we can update that one sentence to mention the high-byte range and how it consequently allows most non-ASCII characters (for better or worse) in names. Previous Comments: ------------------------------------------------------------------------ [2016-02-15 12:48:31] lucas at lucassifoni dot info Description: ------------ According to the PHP doc, «A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.» Some whitespace characters, like U+2000, U+2001, U+2002, U+2003, U+2004 [...], and the zero-width non breaking space (now word joiner, U+FEFF), are interpreted as a part of a function name. If this isn't a problem with a proper code editor that highlights "special" whitespace, it is still conflicting with the doc, and can be really confusing to users. The given snippet has a zero-width nonbreaking space just in front of foo(). When invoking foo(), the function is undefined, since the space is part of its referenced name. Test script: --------------- <?php function foo(){ echo 'bar'; } foo(); Expected result: ---------------- bar Actual result: -------------- Fatal error: Uncaught Error: Call to undefined function foo() in [...][...]:7 Stack trace: #0 {main} thrown in [...][...] on line 7 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71598&edit=1

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