php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25199 $this->a doesn't call $this->__get('a')
Submitted: 2003-08-21 13:05 UTC Modified: 2003-10-16 05:18 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: thomas dot hebinck at digionline dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5* OS: *
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thomas dot hebinck at digionline dot de
New email:
PHP Version: OS:

 

 [2003-08-21 13:05 UTC] thomas dot hebinck at digionline dot de
Description:
------------
A call of $this->a creates a new public variable instead of calling __get('a') - even if this call is just defined and never used. (same problem in beta 1)

Reproduce code:
---------------
<?

class foo {
  function __get($property) {
    switch ($property) {
      case 'a':
      	return 'a';
      	break;
    }
  }
  function bar() {
  	echo 'test';
  	return $this->a; // this is the "bad" line
  }
}

$foo = new foo;

echo '$foo->a = "' . $foo->a . '"';
?>

Expected result:
----------------
$foo->a = "a"

Actual result:
--------------
$foo->a = ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-15 23:54 UTC] kyle at putnamcabinets dot com
Interesting phenomenon:

<?
class foo
{
    //var $a;    // When uncommented, bug always occurs
    function __get($property)
    {
        echo "I behave properly\n";
    }
}

$a = new foo;
//$a->a = 'x';   // When uncommented, bug always occurs
echo $a->a;
?>

No output indicates the bug occurs, otherwise output is "I behave properly".
 [2003-10-16 04:45 UTC] helly@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

When you access a property inside a class method without declaring it it becomes an implicit public property.
 [2003-10-16 04:55 UTC] helly@php.net
Duplicate of #25815
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 08:01:34 2025 UTC