php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67263 Regex incorrect in User-defined functions doc'n
Submitted: 2014-05-13 03:49 UTC Modified: 2014-05-13 15:27 UTC
From: lewis dot berman at verizon dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Windows 7
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: lewis dot berman at verizon dot net
New email:
PHP Version: OS:

 

 [2014-05-13 03:49 UTC] lewis dot berman at verizon dot net
Description:
------------
---
From manual page: http://www.php.net/functions.user-defined
---

Regex in the following text requires a leading caret ("^"):

"A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*."

I.e., the regex should be ^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*. 

Otherwise the subject string '014A7' will match, and that is not in accordance with the text. The script was run under Bitnami wampstack-5.4.28-0.


Test script:
---------------
<?php
 
 $match_result = preg_match("/[a-zA-Z][a-zA-Z0-9]*./", '014A7');
 echo $match_result;
 $match_result = preg_match("/^[a-zA-Z][a-zA-Z0-9]*./", '014A7');
 echo $match_result;
?>


Actual result:
--------------
The script returns 0 for the first match, 1 for the second.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-13 15:27 UTC] levim@php.net
-Status: Open +Status: Not a bug
 [2014-05-13 15:27 UTC] levim@php.net
The regular expression is defining the identity of the function name, not all of the requirements around it. Additionally, in actual code a user-defined function is guaranteed to not be at the start of the string; it will always have `function [&]` come before it.

The documentation could perhaps be improved but it's not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 23:01:28 2024 UTC