php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25898 array returning mechanism from objects?
Submitted: 2003-10-17 13:21 UTC Modified: 2005-05-02 11:20 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: sven at leon dot uia dot mx Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.0b1 (beta1) OS: All (redhat 90)
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: sven at leon dot uia dot mx
New email:
PHP Version: OS:

 

 [2003-10-17 13:21 UTC] sven at leon dot uia dot mx
Description:
------------
Im not sure if it is a bug or not.

with an object inside an object, this is possible:
echo $test->testobject()->color;

with and array inside an object, this is NOT possible:
echo $test->testarray()["color"];

In other words, when an object returns an array, I can not directly access it. 

This will work:
$temparray=$test->testarray();
echo $temparray["color"];


Reproduce code:
---------------
<?php
class c_testobject{
  function __construct(){
    $this->color="red";
	}
}
class c_test{
  private $testobject; private $testarray=array("color" => "red");
  function testobject(){
		$testobject=new c_testobject;
		return $testobject;
  }
  function testarray(){
    return $testarray;
  }
}
$test=new c_test();
echo $test->testobject()->color;
echo $test->testarray()["color"];
?>

Expected result:
----------------
redred

Actual result:
--------------
Parse error: parse error, expecting `','' or `';'' in /var/www/html/php-easy/test.php on line 19

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-02 11:20 UTC] andrey@php.net
AFAIK this is "Won't fix". Brought already on the internals ML but no interest from Z/A.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 01:00:01 2025 UTC