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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 23:01:27 2024 UTC