php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28817 Var problem when extending domDocument
Submitted: 2004-06-17 11:37 UTC Modified: 2005-01-20 12:48 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:2 (33.3%)
From: D dot Kingma at jool dot nl Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-06-17 (dev) OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: D dot Kingma at jool dot nl
New email:
PHP Version: OS:

 

 [2004-06-17 11:37 UTC] D dot Kingma at jool dot nl
Description:
------------
When extending the domDocument class its not possible anymore to fill any class array properties (other properties can still be changed)

Reproduce code:
---------------
class z extends domDocument{
	/** variable can have name */
	var $y=Array();
	var $x;
	function __construct(){
		$this->y['doh']='me';
		$x='aaaaahhhh';
		print_r($this->y);	
		echo $x;
	}	
}
$z=new z();

Expected result:
----------------
Array ( [doh] => me ) aaaaahhhh

Actual result:
--------------
Array ( ) aaaaahhhh

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-19 13:36 UTC] profic at kursknet dot ru
php5.0RC3
the same problem.
But I discovered, that the second assignment do things right
e.g.:
class a extends DOMDocument {
    private $prop = array ();
    public function __construct () {parent::__construct ()}
    public function func () {
        $this->prop[] = 'test';
        $this->prop[] = 'test';
    }
}
$o = new a ();
$o->func ();
var_dump ($o);
 [2004-10-22 12:53 UTC] Jason at amp-design dot net
This is much like the constructor bug in PHP4, because $this in the constructor doesn't properly reference the object being constructed.

One way I normally get round this in PHP4 is to use the Factory pattern, where you do 

class A {

    static public function &Factory() {
        // Use this as a replacement to the constuctor
        $obj = &new A();
        $obj->var = 'Foo Bar';
        return $obj;
    }
}

you just need to construct classes using the static member function like ...

$obj = &A::Factory();

instead of 

$obj = &new A();

e.g.

class z extends domDocument{
	/** variable can have name */
	var $y=Array();
	var $x;
	function __construct(){
		$this->y['doh']='me';
		$x='aaaaahhhh';
		print_r($this->y);	
		echo $x;
	}

	function &Factory() {
		$obj = new z();
		$obj->y['doh2']='me2';
		return $obj;
	}
}
$z= &z::Factory();
print_R($z);

However this to me does seem like a PHP Bug. It's very hard with internal classes to know what behaviours are bugs and "features". A submitted http://bugs.php.net/29092 and apparantly it's not a bug, however there is no mentioning of this in the documentation. As a result the bug is really a documentation bug in my eyes.

Regards
Jason
 [2004-12-04 10:09 UTC] georg@php.net
It's fixed in mysqli now (cvs).

/Georg
 [2004-12-04 12:42 UTC] rrichards@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 [2005-01-11 11:51 UTC] D dot Kingma at jool dot nl
The fix in CVS is reverted
 [2005-01-20 12:48 UTC] rrichards@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC