|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-10-22 11:07 UTC] stas@php.net
[2000-11-05 11:41 UTC] stas@php.net
[2000-12-07 11:55 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jul 15 12:00:01 2026 UTC |
When I run the code below, as it stands. I get the following output - which is clearly incorrect! Cullin Performing test A:... testA: forceError: called holder->test() called! testPrint: a: Param 2 testPrint: b: Param 2 Performing test B:... testB: 1 forceError: called Fatal error: Call to a member function on a non-object in /usr/home/cjw/www/function.php on line 36 <? /* try changing the values for testA and testB */ /* from true to false. You will find that when */ /* testA is called with a false or undefuned */ /* value, PHP will not report any errors */ /* and the testPrint will print incorrect */ /* parameters. - Go figure! cwible@cwible.com */ print "<B>Performing test A:...<BR></B>"; testA(getHashVal('false')); print "<P>"; print "<B>Performing test B:...<BR></B>"; print testB(getHashVal('true')); /* create a new object, then call forceError */ function testA (&$var_a) { print "testA: $var_a<BR>"; $obj = new holder(); forceError(); }; /* create a new object, then call forceError */ /* the only difference here is that $var_a */ /* is not a reference - go figure */ function testB ($var_a) { print "testB: $var_a<BR>"; $obj = new holder(); forceError(); }; /* call a method on an undefined object */ function forceError () { print "forceError: called<BR>\n"; $notanobject->test(); testPrint("Param 1","Param 2"); }; /* just print our parameters */ function testPrint($a,$b) { print "testPrint: a: " . $a . "<BR>\n"; print "testPrint: b: " . $b . "<BR>\n"; }; /* return a value from a hash */ function getHashVal($var) { $hash['true'] = true; unset($hash['false']); return($hash[$var]); } /* a class that just prints text */ class holder { function test() { print "<B>holder->test() called!</B><BR>\n"; return; } }; ?>