How to store objects in array and the retrieve them

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default How to store objects in array and the retrieve them

    Hi,

    I'm trying to store objects in an array and then later I want to
    retrieve the object again. I tried it the following way, but it doesn't
    work.

    $items = array();
    $newItem = new Item();
    array_push($items, $newitem);

    $retrievedItem = $items[0];
    $retrievedItem->display();

    Now I get the message:

    Fatal error: Call to undefined function: display() in ...

    So $retrievedItem is not of class Item. How can I retrieve it so it is
    an object of class Item?

    J.P.
    J.P. Guest

  2. Similar Questions and Discussions

    1. store/retrieve images to server
      Hi All, I want to retrieve images from server and send them back to Servlet without using FileUpload. It's an urgent requirement please help me out....
    2. Insert and Retrieve binary objects with MS-SQL 2000
      Alrighty then, I have searched the web abd CF forums for the past 2 months trying to find a code snippet for inserting a binary object into a...
    3. store and retrieve flash in and from database
      Hi all, i stored an uploaded flash-file in a MS-SQL database. Now i want to retrieve this file from my database in ASP.NET, but I don't know how to...
    4. Retrieve Client Certificate using COM Objects
      Anybody knows how to retrieve Client Certificate using COM objects instead of: var=Request.ClientCertificate("certificate"); Thanks
    5. How to store arrays in hashes or objects?
      I had emailed this query out previously but since I never saw my own email in the digest, I'm assuming that it never made it to the...
  3. #2

    Default Re: How to store objects in array and the retrieve them

    "J.P." wrote:
    > Hi,
    >
    > I’m trying to store objects in an array and then later I want to
    >
    > retrieve the object again. I tried it the following way, but it
    > doesn’t
    > work.
    >
    > $items = array();
    > $newItem = new Item();
    > array_push($items, $newitem);
    >
    > $retrievedItem = $items[0];
    > $retrievedItem->display();
    >
    > Now I get the message:
    >
    > Fatal error: Call to undefined function: display() in ...
    >
    > So $retrievedItem is not of class Item. How can I retrieve it so it
    is
    >
    > an object of class Item?
    >
    > J.P.
    There may be a better solution, but you can always serialize the
    object (see php doc).

    --
    [url]http://www.dbForumz.com/[/url] This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: [url]http://www.dbForumz.com/PHP-store-objects-array-retrieve-ftopict141572.html[/url]
    Visit Topic URL to contact author (reg. req'd). Report abuse: [url]http://www.dbForumz.com/eform.php?p=473383[/url]
    steve Guest

  4. #3

    Default Re: How to store objects in array and the retrieve them

    J.P. wrote:
    > I'm trying to store objects in an array and then later I want to
    > retrieve the object again. I tried it the following way, but it doesn't
    > work.
    >
    > $items = array();
    > $newItem = new Item();
    > array_push($items, $newitem);
    If this is your exact code, it's going to fail because variable names
    are case sensitive. You're pushing an uninitialized variable, hence a
    NULL value.

    When copying objects around you may also want to make sure you
    understand the awful issue of references: [url]http://www.php.net/references[/url]

    -- brion vibber (brion @ pobox.com)
    Brion Vibber Guest

  5. #4

    Default Re: How to store objects in array and the retrieve them

    Brion Vibber wrote:
    > J.P. wrote:
    >
    >> I'm trying to store objects in an array and then later I want to
    >> retrieve the object again. I tried it the following way, but it
    >> doesn't work.
    >>
    >> $items = array();
    >> $newItem = new Item();
    >> array_push($items, $newitem);
    >
    >
    > If this is your exact code, it's going to fail because variable names
    > are case sensitive. You're pushing an uninitialized variable, hence a
    > NULL value.
    >
    > When copying objects around you may also want to make sure you
    > understand the awful issue of references: [url]http://www.php.net/references[/url]
    >
    > -- brion vibber (brion @ pobox.com)
    No, this isn't my exact code. I'm quite new to PHP, but not to
    programming. But I figured my problem out. Programming OOP in PHP is
    slightly different than in p.e. Java.
    Thanks anyway.

    J.P.
    J.P. Guest

  6. #5

    Default Re: How to store objects in array and the retrieve them

    steve wrote:
    > "J.P." wrote:
    > > Hi,
    > >
    > > I’m trying to store objects in an array and then later I want to
    > >
    > > retrieve the object again. I tried it the following way, but it
    > > doesn’t
    > > work.
    > >
    > > $items = array();
    > > $newItem = new Item();
    > > array_push($items, $newitem);
    > >
    > > $retrievedItem = $items[0];
    > > $retrievedItem->display();
    > >
    > > Now I get the message:
    > >
    > > Fatal error: Call to undefined function: display() in ...
    > >
    > > So $retrievedItem is not of class Item. How can I retrieve it so it
    > is
    > >
    > > an object of class Item?
    > >
    > > J.P.
    >
    > There may be a better solution, but you can always serialize the
    > object (see php doc).
    >
    Serialization is indeed an option, but I could not use it here. But
    after a few hours i figured it out. The problem was somewhere else.
    Thanks anyway.

    J.P.
    J.P. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139