(Fwd) Re: [PEAR-DEV] [RFC/PATCH]: push/popErrorHandling() in a

From: Date: Mon, 01 Mar 2004 10:24:53 +0000
Subject: (Fwd) Re: [PEAR-DEV] [RFC/PATCH]: push/popErrorHandling() in a
Groups: php.pear.qa 
Request: Send a blank email to pear-qa+get-778@lists.php.net to get a copy of this message
Should we maybe incorporate an is_a-check in there, as suggested here, not just a isset($this)-check? As Pierre knows, we've come across a similar problem in the Validate- package when running the tests: $this was set although no instance of Validate was created but the function was called statically. This resulted from the fact that the unit-tests are an instance (object) and therefor $this was set to the unit-testing framework. Wouldn't have expected this - but that's what I experienced. Feedback strongly appreciated! Stefan ------- Forwarded message follows ------- From: Markus Kalkbrenner <markus.kalkbrenner@arcor.de> To: pear-dev@lists.php.net Date sent: Mon, 1 Mar 2004 11:21:48 +0100 Subject: Re: [PEAR-DEV] [RFC/PATCH]: push/popErrorHandling() in a class [ Double-click this line for list subscription options ] Hi! First of all, I'm new to this list. Greg Beaver told me to join this list and post my suggestions here. I really had some trouble due to the fact that PEAR::setErrorHandling() and PEAR::pushErrorHandling() use isset($this) to find out if the methods are called staticly. > I've attached my testcase, and a patch which fixes the problem for > me. It won't call $this->push/popErrorHandling() unless the class > extends PEAR. This enhancement, which is part of PEAR 1.3, works for some cases but isn't safe too. See my example I posted at http://pear.php.net/bugs/bug.php?id=744&thanks=3 So what you really need is a safe way to decide if a method is called staticly or not. For PHP versions >= 4.3 I suggested a workaround: if (function_exists("debug_backtrace") { $call = reset(debug_backtrace()); } else { // assume non static call for PHP < 4.3 $call = array('type' => "->"); } // safe check for PHP >= 4.3 and sometimes working for PHP < 4.3 if (isset($this) && is_a($this, 'PEAR') && $call['type'] == "->") { // non static call } else { // static } Comments about this workaround are welcome. Regards, Markus Kalkbrenner -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ------- End of forwarded message -------

« previous php.pear.qa (#778) next »