php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9618 Strange behaviour initialing extended class
Submitted: 2001-03-08 06:51 UTC Modified: 2001-03-08 07:18 UTC
From: arzga at tky dot hut dot fi Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: linux/rh7.0 std
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: arzga at tky dot hut dot fi
New email:
PHP Version: OS:

 

 [2001-03-08 06:51 UTC] arzga at tky dot hut dot fi
Hi,

PHP acts strangely when calling a parent class constructor from an extended class. PHP4 seems to call the constructor without arguments instead of the one with the right number of arguments.

Regards,
Ari Nyk?nen

// -------- clip clip clip ----------------

<script language="php">
	class Huikkari {
		var $huikkasana="initial";
		function Huikkari($huikkasana) {
			$this->huikkasana=$huikkasana;
		}
		function Huikkari() {
			$this->huikkasana="default";
		}
		function huikkaa () {
			echo ($this->huikkasana."\n");
			return true;
		}
	}

	class HelloHuikkari extends Huikkari {
		function helloHuikkari () {
// *** possible problem here *** the following line seems
// to call the Huikkari constructor with no arguments
			$this->Huikkari('Hello World');
		}
	}

	$helloHuikkari = new HelloHuikkari();
// I think the following line should
// output 'Hello World' instead of 'defaultt'
	$helloHuikkari->huikkaa();

</script>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-08 07:18 UTC] stas@php.net
PHP is not C++, you cannot have two functions with same
names and different parameters.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 12:01:29 2025 UTC