Re: How to read (or adjust) a single entry of an object wich comes from an array



--
FREE Avatar hosting at www.easyavatar.com
"T. Wintershoven" <twintershoven@xxxxxxxxx> wrote in message
news:JM6dnTjyCIvMi23ZRVnyug@xxxxxxxxxxxx
English version:
Hi
In a simple testcode i made a few objects from an array.
This works fine when i read the objects with a foreach statement. (see
code
below)

But when i trie to read a single object from this array, i get an
errormessage that an unexpected [ exists on line x
if($objCar[1]->$this->m_sColor=="Blue")

I searched the internet and found something that could bring the solution.
Place the wanted object in a variable first and than read it.
$oCar=$objCar[1];
if($oCar->$this->m_sColor=="Blue")
I now get an errormessage Fatal error: Cannot use object of type clsCar as
array in /cursusaccounts/twintershovedu/site/OOAuto1.php on line 60

My question is:
How can i read a single object wich is created from an array so that the
code below does work.

------------------ The
Code ----------------------------------------------------
$aCar = array();

$aCar[0] = new clsCar("Mercedes", "A180", "Beige");
$aCar[1] = new clsCar("Toyota", "Avensis", "Blauw");
$aCar[2] = new clsCar("Volvo", "440", "Wit");

foreach($aCar as $objCar)
{
$objCar->printCarProperties();
}

//Till this point all works fine..... but then......

$oCar=$objCar[1];

if($oCar->$this->m_sColor=="Blue")
{
echo"<br>Yes... This car is blue";
}
--------------------------------------------------------------------------
--
---------
Thanks in advanced
Tino Wintershoven
The Netherlands



You need to do:

$objCar[0]->m_sColor == 'Blue'; // or is it Blauw ?

when outside of the class and refering to the class.

$this->m_sColor = 'Blue'; // or is it Blauw ?

when inside the class refering to the class itself

---
class clsCar
{ // php3/4 style
var $m_sMake = '';
var $m_sModel = '';
var $m_sColor = '';

function clsCar($args = array())
{ // called whenever you create the class in your script as are the
variable set above
if (isset($args[0]))
{
$this->m_sMake = $args[0];
}
if (isset($args[1]))
{
$this->m_sModel = $args[1];
}
if (isset($args[2]))
{
$this->m_sColor = $args[2];
}
}
}

---
Norm


.



Relevant Pages

  • Re: TrySetLength not possible !? :(
    ... The length of the array is supposed to be the number of elements. ... function SkybuckTrySetLength(var ParaVar; const ParaNewLength: ... vWord: array of Word; ... vLongword: array of Longword; ...
    (alt.comp.lang.borland-delphi)
  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreOldVals ... ' store values of current row in array ... Dim n As Integer, intlast As Integer ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreOldVals ... ' store values of current row in array ... Dim n As Integer, intlast As Integer ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreOldVals ... ' store values of current row in array ... Dim n As Integer, intlast As Integer ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)