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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 20:01:35 2024 UTC