php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22241 Incorrect fatal error when calling a method on a class from within a function
Submitted: 2003-02-16 06:17 UTC Modified: 2003-02-16 16:43 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: philippe-php at girolami dot org Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.3.0 OS: Linux web13.90.ha.ovh.net 2.4.20
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: philippe-php at girolami dot org
New email:
PHP Version: OS:

 

 [2003-02-16 06:17 UTC] philippe-php at girolami dot org
PHPInfo for the server is here : http://90plan.ovh.net/phpinfo.php

The code is here :
<pre>
<?php
class Toto
{
	var $port;

	function Toto($string)
	{
		$this->port=$string;
		echo "<br><br>TOTO constructor was called so class was found!! Dumping vars:<br><i>";
		var_dump($this);
		echo"</i><br>";
	}
	
	function test()
	{
		echo "<br><br><b>method <i>test</i> called.</b> Value for port is :".$this->port;
	}
}

	$toutou=new Toto("PORT1");
	$toutou->test();
	echo "<hr>Entering function and doing the same calls with value PORT2";
	testCallsInFunction();

function testCallsInFunction()
{

	$toutou2=new Toto("PORT2");
	$toutou->test();
}
?></pre>

The output I get is 
<pre>
TOTO constructor was called so class was found!! Dumping vars:
object(toto)(1) { ["port"]=> string(5) "PORT1" } 


method test called. Value for port is :PORT1
--------------------------------------------------------------------------------
Entering function and doing the same calls with value PORT2

TOTO constructor was called so class was found!! Dumping vars:
object(toto)(1) { ["port"]=> string(5) "PORT2" } 

Fatal error: Call to a member function on a non-object in /home/eurobill/www/toto.php on line 29
</pre>

I have tried including the class in another file and adding an include statement inside the function but it still doesn't work. This bug forced me to remove calls to objects in functions for my site !

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-16 11:06 UTC] philippe-php at girolami dot org
I do not have root access on the server as this is a shared server. Perhaps someone else can try
 [2003-02-16 11:43 UTC] sniper@php.net
After fixing that typo in the testCallsInFunction(), it works just fine.

hint: $toutou->test()  -> $toutou2->test() 

 [2003-02-16 16:43 UTC] philippe-php at girolami dot org
I'm sorry about that. I will rework on the submission next weekend because there is a bug lurking...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 11:01:29 2024 UTC