#25714 [NEW]: static calls of PEAR::setErrorHandling within classes

From: Date: Wed, 01 Oct 2003 13:57:14 +0000
Subject: #25714 [NEW]: static calls of PEAR::setErrorHandling within classes
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-22269@lists.php.net to get a copy of this message
From: kalkbrenner at jobpilot dot com Operating system: Linux PHP version: Irrelevant PHP Bug Type: PEAR related Bug description: static calls of PEAR::setErrorHandling within classes Description: ------------ If you call PEAR::setErrorHandling(...) staticly to change the global error handling temporarily within a method of a class, it won't work if you aterwards call a method of another class which itself calls a method of another class that extends PEAR and raises an error. (confusing, but see example) Exactly this happens if you want to change the error handling before you call DB::connect($dsn) within a method of your own class, because DB::connect intantiates p.e. DB_mysql and calls DB_mysql::connect which raises en error if it runs into problems. Assumption: The check for isset($this) in PEAR::setErrorHandling doesn't face this situation. If you call var_dump($this) in PEAR::setErrorHandling when running my example, you'll see that it returns the Instigator. This is a known issue about PHP. Extending the check to see if the value of $this inherits PEAR isn't a solution because classes like Instigator might extend PEAR as well. Markus Kalkbrenner Reproduce code: --------------- <?php require_once("PEAR.php"); class Instigator { function doSomething() { PEAR::setErrorHandling(PEAR_ERROR_DIE); // won't work Killer::doSomething(); } } class Killer { function doSomething() { $victim = & new Victim(); $victim->doSomething(); print "He's still alive!"; } } class Victim extends PEAR { function doSomething() { return $this->raiseError("I'm dead!", 0); } } PEAR::setErrorHandling(PEAR_ERROR_RETURN); $instigator = new Instigator(); print "<br>first try: "; $instigator->doSomething(); PEAR::setErrorHandling(PEAR_ERROR_DIE); // works print "<br>second try: "; $instigator->doSomething(); ?> Expected result: ---------------- first try: He's still alive! second try: I'm dead! -- Edit bug report at http://bugs.php.net/?id=25714&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25714&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25714&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=25714&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=25714&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=25714&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=25714&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=25714&r=support Expected behavior: http://bugs.php.net/fix.php?id=25714&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=25714&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=25714&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=25714&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25714&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=25714&r=dst IIS Stability: http://bugs.php.net/fix.php?id=25714&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=25714&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=25714&r=float

« previous php.pear.dev (#22269) next »