php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73049 Confusing namespace when calling missing function
Submitted: 2016-09-08 15:10 UTC Modified: 2021-05-22 14:34 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: david at grudl dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
28 - 10 = ?
Subscribe to this entry?

 
 [2016-09-08 15:10 UTC] david at grudl dot com
Description:
------------
When you call undefined global function inside namespace, the error message contains namespace, which is usually confusing.

Example: Suppose that I have not enabled extension 'json' by mistake. Now this code

<?php

namespace Nette;

echo json_encode($x); 

?>

leads to error "Call to undefined function Nette\json_encode()". The better message should be "Call to undefined function json_encode()".

I know how works function name resolution, but consider these points:

1) functions are used in namespaces only rarely
2) functions are usually called without leading slash, i.e. not fully qualified
3) both error messages are correct, none is more correct than the other

So it is much more likely that I call a global function, so it would be preferable to use message WITHOUT namespace.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-08 16:57 UTC] cmb@php.net
In my opinion the current error message is preferable over your
suggestion, because looking for a global function (or constant for
that matter) is only a *fallback*.
 [2021-05-22 14:34 UTC] krakjoe@php.net
-Status: Open +Status: Wont fix
 [2021-05-22 14:34 UTC] krakjoe@php.net
As stated, the function you invoked is namespace\name, \name is a fallback and should not appear in the error message.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC