Ask a Question related to PHP Development, Design and Development.
-
J.P. #1
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
-
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.... -
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... -
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... -
Retrieve Client Certificate using COM Objects
Anybody knows how to retrieve Client Certificate using COM objects instead of: var=Request.ClientCertificate("certificate"); Thanks -
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... -
steve #2
Re: How to store objects in array and the retrieve them
"J.P." wrote:
is> 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 itThere may be a better solution, but you can always serialize the>
> an object of class Item?
>
> J.P.
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
-
Brion Vibber #3
Re: How to store objects in array and the retrieve them
J.P. wrote:
If this is your exact code, it's going to fail because variable names> 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);
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
-
J.P. #4
Re: How to store objects in array and the retrieve them
Brion Vibber wrote:
No, this isn't my exact code. I'm quite new to PHP, but not to> 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)
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
-
J.P. #5
Re: How to store objects in array and the retrieve them
steve wrote:
Serialization is indeed an option, but I could not use it here. But> "J.P." wrote:> is> > 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>> >
> > an object of class Item?
> >
> > J.P.
> There may be a better solution, but you can always serialize the
> object (see php doc).
>
after a few hours i figured it out. The problem was somewhere else.
Thanks anyway.
J.P.
J.P. Guest



Reply With Quote

