php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21845 $this in static calls
Submitted: 2003-01-23 10:27 UTC Modified: 2003-08-13 15:36 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: cynic@php.net Assigned: cellog (profile)
Status: Closed Package: PEAR related
PHP Version: 4.3.2 OS: na
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cynic@php.net
New email:
PHP Version: OS:

 

 [2003-01-23 10:27 UTC] cynic@php.net
I'm sure I've seen this discussed on php-dev@, but cannot find it for the life of me, nor do I recall the conclusion.

class foo {
  function bar () {
    baz::quux();
  }
}

class baz {
  function quux() {
    printf('$this is %s set', isset($this)?'':'not')
  }
}

PEAR_Error::throwError() suffers from this bug.

two alternate patches:
Index: pear/PEAR.php
===================================================================
RCS file: /repository/php4/pear/PEAR.php,v
retrieving revision 1.53
diff -u -u -r1.53 PEAR.php
--- pear/PEAR.php	21 Jan 2003 13:32:34 -0000	1.53
+++ pear/PEAR.php	23 Jan 2003 16:20:52 -0000
@@ -528,7 +528,7 @@
                          $code = null,
                          $userinfo = null)
     {
-        if (isset($this)) {
+        if (isset($this) && is_subclass_of($this, 'PEAR_Error')) {
             return $this->raiseError($message, $code, null, null, $userinfo);
         } else {
             return PEAR::raiseError($message, $code, null, null, $userinfo);


Index: pear/PEAR.php
===================================================================
RCS file: /repository/php4/pear/PEAR.php,v
retrieving revision 1.53
diff -u -u -r1.53 PEAR.php
--- pear/PEAR.php	21 Jan 2003 13:32:34 -0000	1.53
+++ pear/PEAR.php	23 Jan 2003 16:20:34 -0000
@@ -528,7 +528,7 @@
                          $code = null,
                          $userinfo = null)
     {
-        if (isset($this)) {
+        if (isset($this) && method_exists($this, 'raiseError')) {
             return $this->raiseError($message, $code, null, null, $userinfo);
         } else {
             return PEAR::raiseError($message, $code, null, null, $userinfo);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-08 09:14 UTC] alan_k@php.net
I think Andi confirmed this behaviour will disappear in PHP5 (the $this transfer on static methods), 

Probably worth emailing Stig or pear-dev to confirm that nobody has a problem with this (patch  looks ok to me)
 [2003-03-13 15:10 UTC] mj@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-03-13 15:23 UTC] cynic@php.net
*what* was fixed? was the $this transfer fixed, or was PEAR_Error::throwError() patched to work around it?
 [2003-03-13 15:29 UTC] mj@php.net
throwError() has been patched for now.
 [2003-07-31 15:28 UTC] cellog@php.net
There are a few other functions that need a similar patch.  If it looks good, I'm happy to commit this patch.

Greg

Index: pear/PEAR.php
===================================================================
RCS file: /repository/php-src/pear/PEAR.php,v
retrieving revision 1.65
diff -u -r1.65 PEAR.php
--- pear/PEAR.php	10 Jul 2003 11:35:37 -0000	1.65
+++ pear/PEAR.php	31 Jul 2003 20:25:56 -0000
@@ -289,7 +289,8 @@
 
     function setErrorHandling($mode = null, $options = null)
     {
-        if (isset($this)) {
+        if (isset($this) &&
+            (get_class($this) == 'pear' || is_subclass_of($this, 'pear'))) {
             $setmode     = &$this->_default_error_mode;
             $setoptions  = &$this->_default_error_options;
         } else {
@@ -566,7 +567,8 @@
     function pushErrorHandling($mode, $options = null)
     {
         $stack = &$GLOBALS['_PEAR_error_handler_stack'];
-        if (isset($this)) {
+        if (isset($this) &&
+            (get_class($this) == 'pear' || is_subclass_of($this, 'pear'))) {
             $def_mode    = &$this->_default_error_mode;
             $def_options = &$this->_default_error_options;
         } else {
@@ -575,7 +577,8 @@
         }
         $stack[] = array($def_mode, $def_options);
 
-        if (isset($this)) {
+        if (isset($this) &&
+            (get_class($this) == 'pear' || is_subclass_of($this, 'pear'))) {
             $this->setErrorHandling($mode, $options);
         } else {
             PEAR::setErrorHandling($mode, $options);
@@ -600,7 +603,8 @@
         array_pop($stack);
         list($mode, $options) = $stack[sizeof($stack) - 1];
         array_pop($stack);
-        if (isset($this)) {
+        if (isset($this) &&
+            (get_class($this) == 'pear' || is_subclass_of($this, 'pear'))) {
             $this->setErrorHandling($mode, $options);
         } else {
             PEAR::setErrorHandling($mode, $options);

 [2003-08-08 14:24 UTC] cellog@php.net
This bug renders setErrorHandling() useless inside a class that doesn't extend PEAR, and is therefore kind of important.  I'd like to commit the patch I posted previously for 4.3.3's release.  All it does is change the test of if (isset($this)) to if (isset($this) && (get_class($this) == 'pear' || is_subclass_of($this, 'pear'))), ensuring correct behavior (the static handling should be used in a class that is not a PEAR descendant)

Greg
 [2003-08-13 15:36 UTC] cellog@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC