php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63201 Function overloading with namespace
Submitted: 2012-10-02 15:26 UTC Modified: 2017-03-11 18:06 UTC
Votes:54
Avg. Score:4.1 ± 0.9
Reproduced:42 of 44 (95.5%)
Same Version:38 (90.5%)
Same OS:17 (40.5%)
From: brainreflex at gmail dot com Assigned:
Status: Duplicate Package: Unknown/Other Function
PHP Version: * OS: *
Private report: No CVE-ID: None
 [2012-10-02 15:26 UTC] brainreflex at gmail dot com
Description:
------------
5.4 doesn't allow to redefine function if bult-in function had been called 
before. It's a bug or omission of documentation

For more details look at http://vatson.com.ua/blog/2012/10/01/php-5-dot-4-and-
function-overloading/

Test script:
---------------
https://github.com/vatson/php-experiments

Expected result:
----------------
The same behavior for both versions


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-20 00:50 UTC] sjaillet at gmail dot com
Looks like it's an introduced bug since redefining functions still works well when functions had been called in the same file like the following :

<?php
namespace custom;

var_export('hello'); //hello

eval("namespace custom; function var_export(){echo 'foobar';}");

var_export('hello'); //foobar
?>
 [2013-04-21 21:14 UTC] sjaillet at gmail dot com
It's pretty annoying since this feature allowed a king of monkey patching in PHP 5.3 for writing tests cases.

With PHP 5.4 & 5.5, redefining functions only work in the same file like in the follwing example:

<?php
namespace custom;

var_export('hello'); //hello

eval("namespace custom; function var_export(){echo 'foobar';}");

var_export('hello'); //foobar
?>
 [2014-07-15 11:47 UTC] yohgaki@php.net
-Summary: PHP 5.4 and Function Overloading +Summary: Function overloading with namespace -Status: Open +Status: Verified -Operating System: OS X 10.7.5 +Operating System: * -PHP Version: 5.4.7 +PHP Version: *
 [2017-03-11 18:06 UTC] nikic@php.net
-Status: Verified +Status: Duplicate
 [2017-03-11 18:06 UTC] nikic@php.net
Marking as duplicate of bug #64346.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu May 23 07:01:40 2019 UTC