php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17708 argument passing problem
Submitted: 2002-06-11 12:47 UTC Modified: 2002-08-14 17:42 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: tsullivan at nforce dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.1.2 OS: FreeBSD 4.3
Private report: No CVE-ID: None
 [2002-06-11 12:47 UTC] tsullivan at nforce dot com
/****************** From phpinfo() ******************/

 './configure' '--with-apxs=/usr/local/sbin/apxs' '--with-config-file-path=/usr/local/etc' '--enable-versioning' '--with-system-regex' '--disable-debug' '--enable-track-vars' '--without-gd' '--without-mysql' '--with-gd=/usr/local' '--with-freetype-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-zlib' '--with-imap=/usr/local' '--with-mysql=/usr/local' '--with-ldap=/usr/local' '--prefix=/usr/local' 'i386--freebsd4.3'

/*******************************************************/

The script is made up of several files. It doesn't produce a standard PHP error, rather the browser (IE5) says that the server sent an unrecognized response. The script executes fine if I comment out the line in question.

Here is the requested URI:
/*******************************************************/
<?php
require_once("TsTestBoundObject.class.php");
session_start();

if ($HTTP_GET_VARS["reset"]==1) {
	session_destroy();
	session_start();
}

if (!is_object($_SESSION["tester"])) {
	$_SESSION["tester"]=& new TsTestBoundObject("Hello World!<br>\n");
	$_SESSION["test2"]=& new TsTestBoundObject("Hello World!<br>\n");
}

echo $_SESSION["tester"]->UOID;  //WORKS FINE
echo $_SESSION["test2"]->UOID;   //WORKS FINE TOO

$temp = $_SESSION["tester"];   //ALL GOOD
$temp2 = $_SESSION["test2"];   //ALL GOOD

//$temp->setRelation("isParentOf", $temp2, "isChildOf");
echo $temp->content;   //WORKS FINE
$temp->test("hello?", $temp2);   

?>
/***************** END REQUESTED URI ********************/

The third last line (which is commented out) was what originally caused the error. That led me to create a method called test() in the same base class as setRelation() (note that object $temp belongs to a derived class of the class in which i defined test() and setRelation().

When I implemented test() like below, I get the expected results:

	function test($something, &$c) {
		echo $something;
		echo $c->content;
	}

This produced a normal result, the string I passed in the call followed by $c->content, which was set to "Hello world".

However, as soon as I changed the method to resemble the prototype of the method that was originally messed up (setRelation()), I got a very weird result:

	function test($something, &$c, $somethin2="") {
		echo $something;
		echo $c->content;
		echo $somethin2;
	}

In this scenario, I called the above method like this:

$temp->test("Hello", $temp2);

Which should have produced the SAME output. Instead, it only prints out $temp2->content ("Hello World") and acts as though the $something was non-existent. Calling it with the third argument explicitly listed in the call resulted in the same thing.

This led me to the conclusion that because of the argument count mismatch combined with the interpreter's lack of knowledge about the mismatch, PHP generated some type of weird output that caused my browser to get confused.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-11 12:55 UTC] tsullivan at nforce dot com
/********** ADDITION ************/

Wow, weird.
First, $temp->content was set to the string "test2".

Now I just called this:

$temp->test("hello?", $temp2, "hello again?");

where I defined test() as:

	function test($something, &$c, $somethin2) {
		echo $something;
		echo $c->content;
		echo $somethin2;
	}

and the output was:

hello again?test2
hello again? 

So in this instance, the string passed in the third argument was copied to $something and $somethin2???
 [2002-06-16 10:52 UTC] peak at uni dot de
i experienced the same problem using php 4.1.2 and debian 3.0. when calling class methods with several arguments, the first argument is sometimes (not always!) overwritten by the last one!
 [2002-08-14 17:42 UTC] tal@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 06 16:01:26 2024 UTC