|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28240 class member assigment without declaration defines new member
Submitted: 2004-04-30 22:30 UTC Modified: 2004-05-04 09:01 UTC
From: php at jort dot net Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0RC2 OS: Win2000 Pro
Private report: No CVE-ID: None
 [2004-04-30 22:30 UTC] php at jort dot net
When you assign a value to a class member that was not declared the system defines a new class member.
I'm not sure this is a feature or a bug.
I would expect an error or at least a notice or a warning.

Reproduce code:
class foo {
 function __construct() {
  $this->foo = "test";

$bar = new foo();

print $bar->foo;


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-04 05:51 UTC] phpbug at gb404 dot com
It is totally normal.

As far as I can remember, PHP never needed to declare a variable before using it.
 [2004-05-04 09:01 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 07:01:28 2024 UTC