Arrrgh! OOP PHP4 PHP5 create properties on the fly

Discussion in 'PHP' started by obiron, Jun 5, 2007.

  1. #1
    Guys,

    This is doing my head in…

    Its not really CI related but as you are all PHP experts as well

    I have the following code


    $this->Results->Drivers=  $this->F1_drivers_model->get_alldrivers();
          foreach   ($this->Results->Drivers as $loop)
          {
            $loop->Name = $this->F1_drivers_model->get_drivername($loop->ID);
            $loop->Cost = $this->F1_drivers_model->get_drivercost($loop->ID);
            $loop->TeamID = $this->F1_drivers_model->get_driverteam($loop->ID);
            $loop->TeamName = $this->F1_drivers_model->get_driverteamname($loop->ID);
            print $loop->ID . " " . $loop->Name . " [" . $loop->Cost . "] " . $loop->TeamName . "<BR>";
          } 
    PHP:
    get_alldrivers() just gets an array of objects, each object contains one property ‘->ID’In both PHP4 and PHP5 the print line displays the correct data.
    In PHP5 the values set in loop are available under
    $this->Results->Drivers->object->Name 
    $this->Results->Drivers->object->Cost etc.. 
    PHP:
    The data has been passed to the MVC view as $data[’Drivers’]

    and is retreived by using


    foreach ($Drivers as $Driver);
    {
      print $Driver->Name;
      print $Driver->Cost;
    } 
    PHP:
    This works sucessfully in the development environment (XP pro / Xampp / PHP 5)

    but in live (Linux / Apache / PHP 4) I get the following error message:

    A PHP Error was encountered 
    Severity: Notice 
    
    Message: Undefined property: Name
    PHP:
    any idea how to stop this. I know that returning all the properties as part of the data set means that they are created and availalbe to update, but I would really like to be able to create them on the flu in PHP4.

    Thanks

    Obiron
     
    obiron, Jun 5, 2007 IP
  2. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe try $Driver->name or something?
     
    DeViAnThans3, Jun 9, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    do
    print_r( $Driver );
    PHP:
    and you'll soon find out
     
    krakjoe, Jun 10, 2007 IP