php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50427 Can't predefine variables as objects inside a class
Submitted: 2009-12-09 15:39 UTC Modified: 2009-12-09 18:08 UTC
From: omri dot rules at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.1 OS: Windows XP
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: omri dot rules at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-09 15:39 UTC] omri dot rules at gmail dot com
Description:
------------
I've tried to predefine a variable inside a class as an instance of another class.
The result was a parse error.

Reproduce code:
---------------
<?php
class Foo {
	public $var = 1;
}

class Bar {
	public $obj = new Foo;
	public function __construct() {
		echo $this->obj->var;
	}
}
$a = new Bar;
?>

Expected result:
----------------
1

Actual result:
--------------
Parse error: parse error in C:\wamp\www\try.php on line 7

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 16:00:01 2025 UTC