php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13703 PHP allows function redefinition
Submitted: 2001-10-16 23:14 UTC Modified: 2002-03-26 03:30 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: yasuo_ohgaki at yahoo dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0CVS-2001-10-1 OS: linux 2.4.4/glibc 2.2.2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yasuo_ohgaki at yahoo dot com
New email:
PHP Version: OS:

 

 [2001-10-16 23:14 UTC] yasuo_ohgaki at yahoo dot com
Found this bug while I'm doing copy & paste.
Current CVS version (both HEAD and RC) allows redefinition of function (method). I think this should be fixed before 4.1.0 release.

Following code compiles/runs. PHP executes first function test().

<?php

class A 
{
	function test()
	{
		echo "A->test()\n";
	}

	function test() 
	{
		echo "Another A->test()\n";
	}
}

$obj = new A;
$obj->test();

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-17 02:01 UTC] mfischer@php.net
When reading your report I get the impression that the script outputs "A->test()\n" because you said "PHP executes first function test()".

I get no redefinition error but on my system the second function is called so my output is "Another A->test()".

So, two we have two different behaviours here or were your report not accurat?

Anyway, it doesn't look good.

- Markus
 [2001-10-17 03:37 UTC] yasuo_ohgaki at yahoo dot com
I get only "A->test()" which is the first function definition. I'm not suprised.

When I notice this bug in much complex scripts that have relatively complex class strucutre, PHP executed both functions that have the same name. (without error/warning)

Does this bug's behaviour depend on configuration?
If anyone need configure line, let me know.
 [2001-11-11 21:29 UTC] sniper@php.net
I get "Another A->test()" with latest CVS.
Anyone got older (4.0.6) to test this with?

--Jani

 [2001-11-11 21:30 UTC] sniper@php.net
Marking as Critical for now.

 [2001-11-11 21:45 UTC] cnewbill@php.net
Ditto with 4.0.6.

-Chris
 [2001-11-11 22:07 UTC] yasuo_ohgaki at yahoo dot com
Tested with CGI bin, I got

4.0.6: "Another A->test()"
4.0.4pl1: "Another A->test()"

When I got both functions executed, memory is broken by some code. (I have no idea what's the cause of broken memory)


[yohgaki@dev php-4.0.6]$ ./php ~/public_html/bugs/13703/test.php 
X-Powered-By: PHP/4.0.6
Content-type: text/html

Another A->test()


[yohgaki@dev php-4.0.6]$ cat config.nice
#! /bin/sh
#
# Created by configure

"./configure" \
"--without-mysql" \
"--without-pear" \
"--enable-debug" \
"$@"
[yohgaki@dev php-4.0.6]$ 
[yohgaki@dev php-4.0.4pl1]$ ./php ~/public_html/bugs/13703/test.php 
Content-type: text/html; charset=EUC-JP

Another A->test()


[yohgaki@dev php-4.0.4pl1]$ 



 [2002-03-26 03:30 UTC] derick@php.net
Fixed in CVS. Fix will be in PHP 4.2.0.

Derick
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Feb 15 07:00:01 2026 UTC