php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28687 return $value & segmentation fault
Submitted: 2004-06-07 23:40 UTC Modified: 2004-06-08 22:11 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: equake at epmail dot com dot br Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: PHP5-200406081230 OS: Linux 2.4.24
Private report: No CVE-ID: None
 [2004-06-07 23:40 UTC] equake at epmail dot com dot br
Description:
------------
I got a Segmentation Fault every time that I try to return some method that does not exists.

Reproduce code:
---------------
abstract class test {
	function __call($method, $params) {
		if (is_callable(array($this, $method))) {
			echo ("ok<br>");
			return $this->{$method}($params); // abstract class test {
	function __call($method, $params) {
		if (is_callable(array($this, $method))) {
			echo ("ok<br>");
			return $this->{$method}($params); // [error_log] [notice] child pid # exit signal Segmentation fault (11)
		}
	}
}

class test2 extends test {
	function  __construct() {
		echo ("hi, im test2 at ". time () ." seconds since 01/01/1970 <br>");
	}
	function bla() {
		echo ('haha');
	}
}

$x = new test2();
$x->bla_inexistent(); // any inexistent method name
		}
	}
}

class test2 extends test {
	function  __construct() {
		echo ("hi, im test2 at ". time () ." seconds since 01/01/1970 <br>");
	}
	function bla() {
		echo ('haha');
	}
}

$x = new test2();
$x->bla_inexistent(); // any inexistent method name

Expected result:
----------------
hi, im test2 at 1086644752 seconds since 01/01/1970 

Actual result:
--------------
"[error_log] [notice] child pid # exit signal Segmentation fault (11)" on the apache Error Log

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-08 09:46 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip
 [2004-06-08 15:42 UTC] equake at epmail dot com dot br
I'm still having problems with the CVS-PHP5-200406081230

[Tue Jun 08 10:43:03 2004] [notice] child pid 2711 exit signal Segmentation fault (11)

But I think that the problem only happen when I try to return a inexistent method inside a abstract class. The following code works well (no segmentation fault):

class test {
	function call($method, $params=null) {
		if (is_callable(array($this, $method))) {
			return $this->{$method}($params);
		} else {
			echo ("not found");
		}
	}

	function message() {
		return "TESTE DE MENSAGEM";
	}
}

$test = new test();
$var = $test->call("not_exist");
echo $var;
 [2004-06-08 15:47 UTC] equake at epmail dot com dot br
the (correct) small script that throws the error:

abstract class test {
	function __call($method, $params) {
		if (is_callable(array($this, $method))) {
			echo ("ok<br>");
			return $this->{$method}($params); // [error_log] [notice] child pid # exit signal Segmentation fault (11)
		}
	}
}

class test2 extends test {
	function  __construct() {
		echo ("hi, im test2 at ". time () ." seconds since 01/01/1970 <br>");
	}
	function bla() {
		echo ('haha');
	}
	function x() {
	}
}

$x = new test2();
$x->xjhjk(); // any inexistent method name
 [2004-06-08 15:58 UTC] equake at epmail dot com dot br
hmm
the problem seems to happen ONLY when I try to return a inexistent method from the __call method


class test {
	function __construct() {
		echo ("script started at ".time()."<br>\n");
	}
	function __call($method, $params) {
		if ($method == "foo") {
			return $this->foo_method();
		} else {
			return $this->buggy();
		}
	}

	function foo_method() {
		return "TESTE DE MENSAGEM";
	}
}

$test = new test();
$var = $test->foo(); // works 
$var2 = $test->foo2(); // segmentation fault
 [2004-06-08 16:10 UTC] tony2001@php.net
This behaviour is caused by endless loop:
non-ex method -> __call -> non-ex method -> __call -> .. etc.
Try to call this func:
function foo() {
 return foo();
}
and you'll get the same result.
not a bug, though.
 [2004-06-08 22:11 UTC] equake at epmail dot com dot br
So PHP shouldn't show a "decent" error message in this situation?

I think that it's not so important when you have a static script that  you're working on a text editor, but it can be a major problem where you are generating php code "automagically" from a XML + XSLT, for example. Sometimes my (erroneous) generated script dies, without *any* message :/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 13:01:30 2024 UTC