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
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: 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)

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 07:01:32 2025 UTC