php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63623 unexpected behaviour of array when referenced from within double apostrophe
Submitted: 2012-11-27 12:22 UTC Modified: 2012-11-27 12:27 UTC
From: reayn3 at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Xubuntu Linux 3.0.0-12-generic
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: reayn3 at gmail dot com
New email:
PHP Version: OS:

 

 [2012-11-27 12:22 UTC] reayn3 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.array
---
While using an echo command with a double apostrophe argument that includes an array variable, the name of the Array object is outputted rather than the actual value for the array item

Test script:
---------------
<?php

Class T {
        private $a = array("c","d") ;

        public function f() {
                return "$this->a[1]" ;
        }
}

$c = new T() ;
echo $c->f() ;



Expected result:
----------------
d

Actual result:
--------------
Array[1]

Patches

fix_for_array_output (last revision 2012-11-27 12:23 UTC by reayn3 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-27 12:27 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-11-27 12:27 UTC] aharvey@php.net
You need to use the complex syntax: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex — "{$this->a[1]}" will work as expected.

As the manual says about the simple syntax: "Similarly, an array index or an object property can be parsed" — you can't have both an object property and an array index.

Closing NaB.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC