php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11565 classes/objects
Submitted: 2001-06-19 13:22 UTC Modified: 2002-06-18 18:33 UTC
From: i6razi at vdu dot lt Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: UNIX/Windows
Private report: No CVE-ID: None
 [2001-06-19 13:22 UTC] i6razi at vdu dot lt
Hello,


In the following example source:

<?php

class A
{
	var $property = 'string value';

	function methodA()
	{
		echo "$this->property\n";
	}
}

class B
{
	var $objArray   = array();
	var $currentObj = 0;

	function B()
	{
		$this->objArray[$this->currentObj] = new A;
	}

	function methodB($index = 0)
	{
		return $this->objArray[$index];
	}
}

$b = new B;

/*
 * This works:
 */
$b->objArray[$b->currentObj]->methodA();

/*
 * But this don't:
 */
// $b->methodB()->methodA();

?>

Is it possible to get this work? It is something like collections in JScript of Internet Explorer, for example:

<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells() {
    var count=0;
    for (i=0; i < document.all.mytable.rows.length; i++) {
        for (j=0; j < document.all.mytable.rows(i).cells.length; j++) {

            // Looks like rows() is method of mytable and
            // cells() is method of object returned by rows()
            document.all.mytable.rows(i).cells(j).innerText = count;
            //                   ~~~~~~~ ~~~~~~~~

            count++;
        }
    }
}
</SCRIPT>
<BODY onload="numberCells()">
<TABLE id=mytable border=1>
<TR><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
</TABLE>
</BODY>
</HTML> 

The following example works in PHP3, but not in PHP4:

<?php

class A
{
	var $var = 'some value';
}

class B
{
	var $date = date('Y.m.d');
	var $a = new A;
}

?>

Is it possible to get it work in PHP4? Maybe, in the future versions of PHP4?

If it's possible let me know about this.


Ramunas

P.s. Sorry for my English.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-20 02:40 UTC] derick@php.net
For both your requests are already feature requests filed.
So I'm marking this one as duplicate. However, I was to lazy to look up the bug id's, and that's why I didn't add them here.

Derick
 [2002-06-18 18:33 UTC] sniper@php.net
IIRC, this is possible in ZE2. Closed.

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 01:01:28 2025 UTC