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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 14:01:33 2025 UTC