Bug #63623 [Opn->Nab]: unexpected behaviour of array when referenced from within double apostrophe

From: Date: Tue, 27 Nov 2012 12:27:07 +0000
Subject: Bug #63623 [Opn->Nab]: unexpected behaviour of array when referenced from within double apostrophe
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-174964@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63623&edit=1

 ID:                 63623
 Updated by:         aharvey@php.net
 Reported by:        reayn3 at gmail dot com
 Summary:            unexpected behaviour of array when referenced from
                     within double apostrophe
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   Xubuntu Linux 3.0.0-12-generic
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-11-27 12:22:57] 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]


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63623&edit=1


Thread (2 messages)

« previous php.bugs (#174964) next »