Edit report at http://bugs.php.net/bug.php?id=52110&edit=1

 ID:               52110
 Comment by:       jbwdevries at gmail dot com
 Reported by:      jbwdevries at gmail dot com
 Summary:          get_defined_vars is inconsistent with $this
 Status:           Bogus
 Type:             Bug
 Package:          Unknown/Other Function
 Operating System: Windows XP [Version 5.1.2600]
 PHP Version:      5.3.2

 New Comment:

I understand your reasoning; however, shouldn't you assume from the use
of get_defined_vars() that $this is needed?


Previous Comments:
------------------------------------------------------------------------
[2010-06-17 17:05:02] johan...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

For performance reasons $this and super-globals are only populated when
they are needed. If the aren't needed they don't exist.

------------------------------------------------------------------------
[2010-06-17 16:40:09] jbwdevries at gmail dot com

Description:
------------
get_defined_vars() only contains the $this variable entry when $this is
assigned or returned. In all other cases (no use, gettting or setting of
property, callign a method) the $this entry is missing from the list.

Test script:
---------------
// Full example is at http://pastebin.com/FDJzCTRG



class Test

{

        //...

        public function testNoThis() {

                echo __METHOD__ . PHP_EOL;

                var_dump(array_keys(get_defined_vars()));

        }

        //...

}



$t = new Test();

$t->testNoThis();



Expected result:
----------------
Test::testNoThis

array(1) {

  [0]=>

  string(4) "this"

}

Test::testThisGet

array(1) {

  [0]=>

  string(4) "this"

}

Test::testThisSet

array(1) {

  [0]=>

  string(4) "this"

}

Test::testThisCall

array(1) {

  [0]=>

  string(4) "this"

}

Test::testThisUse

array(1) {

  [0]=>

  string(4) "this"

}



Actual result:
--------------
Test::testNoThis

array(0) {

}

Test::testThisGet

array(0) {

}

Test::testThisSet

array(0) {

}

Test::testThisCall

array(0) {

}

Test::testThisUse

array(1) {

  [0]=>

  string(4) "this"

}


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52110&edit=1

Reply via email to