within an object function, this code:
$test2[]='test';
echo "$test[0]";
$this->test2[]='test2';
echo "$this->test2[0]\n";
produces this result:
test2
Array[0]
Why do I get Array[0] instead of the value in Array[0] ?
This only seems to happen when the variable is part of an array in an
object. If, for example, I want to wrap an object's variable in single
quotes this doesn't work:
"'$this->test2[0]'"
I can put double quotes areound the single quotes:
"'".$this->test2[0]."'"
but in a long string this becomes very tedious:
"$this->name=['".$this->mbox[0]."','".$this->mbox[1]."',".$this->mbox[2]."];";
is there any way to get "'$this->test2[0]'" to work ?
red 3 1967
The example I gave made no sense so I'll try again.
within an object function, this code:
$test[]='test';
echo "$test[0]";
$this->test2[]='test2';
echo "$this->test2[0]\n";
produces this result:
test
Array[0]
Why do I get Array[0] instead of the value in Array[0] ?
This only seems to happen when the variable is part of an array in an
object. If, for example, I want to wrap an object's variable in single
quotes this doesn't work:
"'$this->test2[0]'"
I can put double quotes areound the single quotes:
"'".$this->test2[0]."'"
but in a long string this becomes very tedious:
"$this->name=['".$this->mbox[0]."','".$this->mbox[1]."',".$this->mbox[2]."];";
is there any way to get "'$this->test2[0]'" to work ?
red
.oO(red) within an object function, this code:
$test[]='test'; echo "$test[0]";
$this->test2[]='test2'; echo "$this->test2[0]\n";
produces this result: test Array[0]
Why do I get Array[0] instead of the value in Array[0] ?
The variable is part of the string, but for the PHP parser it ends after
'$this->test2', which produces the output 'Array'. It works with simple
variables like $test[0], but with more complex structures (like object
properties for example) the parser is not always able to detect which
chars still belong to the variable name and which don't.
This only seems to happen when the variable is part of an array in an object. If, for example, I want to wrap an object's variable in single quotes this doesn't work:
"'$this->test2[0]'"
Same as above.
I can put double quotes areound the single quotes:
"'".$this->test2[0]."'"
but in a long string this becomes very tedious:
"$this->name=['".$this->mbox[0]."','".$this->mbox[1]."',".$this->mbox[2]."];";
is there any way to get "'$this->test2[0]'" to work ?
Yep:
Complex (curly) syntax
<http://www.php.net/manual/en/language.types.string.php#language.types.string.pa rsing.complex>
Micha
Are you instantiating $this->test2 in the constructor?
i.e.
$this->test2 = array();
red <gr****@reenie.org> wrote in message news:<Ls******************@news.easynews.com>... The example I gave made no sense so I'll try again.
within an object function, this code:
$test[]='test'; echo "$test[0]";
$this->test2[]='test2'; echo "$this->test2[0]\n";
produces this result: test Array[0]
Why do I get Array[0] instead of the value in Array[0] ? This only seems to happen when the variable is part of an array in an object. If, for example, I want to wrap an object's variable in single quotes this doesn't work:
"'$this->test2[0]'"
I can put double quotes areound the single quotes:
"'".$this->test2[0]."'"
but in a long string this becomes very tedious:
"$this->name=['".$this->mbox[0]."','".$this->mbox[1]."',".$this->mbox[2]."];";
is there any way to get "'$this->test2[0]'" to work ?
red This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dave.harper |
last post by:
I'm relativly new to C++, and have been looking for a way to
interpolate data (i.e. a table indexed by 2 arrays, or just an array
indexed by another array). I haven't been able to find an easy way...
|
by: Charles Banas |
last post by:
I'm not sure if this is the right place to ask about this, but I've
seen several posts in the past regarding Akima's Bivariate
Interpolations routines, and i'm wondering if someone can give me some...
|
by: Joe Rattz |
last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to
intialize them to false.
bool bits = new bool;
foreach(bool bit in bits)
{
bit = false;
}
The compiler complains...
|
by: Chris Simmons |
last post by:
I know that a String is immutable, but I don't understand why this
piece of code fails in nUnit:
// BEGIN CODE
using System;
class Test
{
public static void Main( String args )
|
by: xandra |
last post by:
i understood the concept of interpolation search.
but i couldn't understand what would be the steps for that search.
for example, if i'm searching for J in this file
A A B E F H J M N N N N O P P...
|
by: different |
last post by:
Hi, I have a program which reads a file containing integers in .
The program reads the value of a variable every 2 seconds, then maps it
to another interval, say , obtaining a new value.
I already...
|
by: MonkeeSage |
last post by:
There are several string interpolation functions, as well as
string.Template. But here's yet another. This one emulates ruby's
inline interpolation syntax (using #{}), which interpolates strings as...
|
by: John Passaniti |
last post by:
(Note: This is not the same message I posted a week or so ago. The
problem that prevented my previous attempt to work was a silly error in
the template system I was using. This is a problem...
|
by: August Karlstrom |
last post by:
Hi,
Does anyone know the correct syntax to interpolate a class variable, $x
say, inside a string? I tried
"{self::$x}"
but it produces the string
{self::x}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |