php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74463 Reserved keywords as function name?
Submitted: 2017-04-18 04:37 UTC Modified: 2017-04-18 05:22 UTC
From: usr at airmail dot cc Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 7.1.4 OS: Mac OS X
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: usr at airmail dot cc
New email:
PHP Version: OS:

 

 [2017-04-18 04:37 UTC] usr at airmail dot cc
Description:
------------
The documentation says:

---
The following words cannot be used to name a class, interface or trait, and they are also prohibited from being used in namespaces.
---
http://php.net/manual/en/reserved.other-reserved-words.php

But it does not mention the use of these words in function names.

Is it safe to use those in the provided manner (see test case)?

Test script:
---------------
<?php
/* This works??? */
namespace A\B {
	function String() {

	}
}
namespace {
	A\B\String();
}
?>

<?php
/* This breaks */
namespace A\B {
	function private() {

	}
}
namespace {
	A\B\private();
}
?>

<?php
/* This also breaks */
namespace A\B {
	class String {}
}
namespace {
	$str = new A\B\String();
}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-18 04:58 UTC] wes at example dot org
Hi, please read https://wiki.php.net/rfc/context_sensitive_lexer
 [2017-04-18 05:13 UTC] usr at airmail dot cc
The RFC states 'restricted to OO scope only'.

However my question is not about OO but rather a function name, so this RFC does not really answer my question.

Or am I overseeing something?
 [2017-04-18 05:17 UTC] usr at airmail dot cc
What further confuses me is that `function Array` is invalid while `function String` is not.

I'm aware that `array()` is a language feature, but shouldn't the keyword enforcing be consistent?
 [2017-04-18 05:22 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-04-18 05:22 UTC] requinix@php.net
When reading documentation, be sure to read *all* the documentation. Not just a couple pages of it.
http://php.net/manual/en/reserved.keywords.php.
"private" and "array" are covered there.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 21:01:29 2024 UTC