FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » accessing nested unknown unserialized objects
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
accessing nested unknown unserialized objects [message #183638] Mon, 04 November 2013 20:37 Go to next message
catseye.chandra is currently offline  catseye.chandra
Messages: 1
Registered: November 2013
Karma: 0
Junior Member
Hello PHP users,

I'm currently fiddling with phpgallery 1.x import/tweaking, and by using unserialize got access to an album metadata.

unserialize gives a big array, with nested objects as each elt.

I cannot find the right way to wright the accessor to two fields of real interest :

$this->image->name

and

$this->caption


for now I got :

<?
$fh = fopen("photos.dat", "r");
$buf = fread($fh, 1024000);
$arr = unserialize($buf);
foreach ($arr as &$o) {
print $o->image->name;
print $o->caption;
flush();
}
?>

also:

<?
$fh = fopen("photos.dat", "r");
$buf = fread($fh, 1024000);
$arr = unserialize($buf);
foreach ($arr as &$o) {
//print_r($o);
printf("%s : %s\n", $o->image->name, $o->caption);
flush();
};
?>

but nothing get printed :-(

Thanks for any help - I'm a beginner.

--

Array
(
[0] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => AlbumItem
[image] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Image
[name] => aaa
[type] => jpg
[width] => 700
[height] => 525
[resizedName] => aaa.sized
[thumb_x] =>
[thumb_y] =>
[thumb_width] =>
[thumb_height] =>
[raw_width] => 1024
[raw_height] => 768
[version] => 38
)
[thumbnail] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Image
[name] => aaa.thumb
[type] => jpg
[width] => 210
[height] => 158
[resizedName] =>
[thumb_x] =>
[thumb_y] =>
[thumb_width] =>
[thumb_height] =>
[raw_width] => 210
[raw_height] => 158
[version] => 38
)
[preview] =>
[caption] => Gymnocalycium saglione - juin 01
[hidden] =>
[highlight] => 1
[highlightImage] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Image
[name] => aaa.highlight
[type] => jpg
[width] => 200
[height] => 150
[resizedName] =>
[thumb_x] =>
[thumb_y] =>
[thumb_width] =>
[thumb_height] =>
[raw_width] => 200
[raw_height] => 150
[version] => 38
)
[isAlbumName] =>
[clicks] => 4659
[keywords] =>
[comments] =>
[uploadDate] => 994366657
[itemCaptureDate] => 992529433
[exifData] => Array
(
[File size] => 160119 bytes
[File date] => 2004:12:29 22:25:11
[Camera make] => NIKON
[Camera model] => E880
[Date/Time] => 2001:06:14 16:37:13
[Resolution] => 1024 x 768
[Flash used] => No
[Focal length] => 13.9mm
[Exposure time] => 0.0080 s (1/125)
[Aperture] => f/9.4
[ISO equiv.] => 100
[Metering Mode] => matrix
[Exposure] => program (auto)
)

[owner] => 988373499_1755202938
[extraFields] => Array
(
)
[rank] => 0
[version] => 38
[emailMe] => Array
(
)

[imageAreas] =>
)
Re: accessing nested unknown unserialized objects [message #183640 is a reply to message #183638] Tue, 05 November 2013 12:11 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
catseye(dot)chandra(at)gmail(dot)com wrote:
^^^^^^^^^^^^^^^^^^^^^^^^^
Please get a name, preferably a real one.

> I'm currently fiddling with phpgallery 1.x import/tweaking, and by using
> unserialize got access to an album metadata.
>
> unserialize gives a big array, with nested objects as each elt.
>
> I cannot find the right way to wright the accessor to two fields of real
> interest :
>
> $this->image->name
>
> and
>
> $this->caption

Apparently you are not within a dynamically called method, so $this has no
meaning.

> for now I got :
>
> <?

Should be

<?php

see also <http://pear.php.net/manual/en/standards.tags.php>.

> $fh = fopen("photos.dat", "r");
> $buf = fread($fh, 1024000);

This may get you an incomplete serialization in $buf. In order to read a
file of unknown size into a string without sending it to the standard
output, use file_get_contents() instead (and handle potential errors).
(1024000 bytes are 1024 kB, not 1024 KiB = 1 MiB.)

You also forgot to fclose() after that. Although not strictly necessary
here (that is, *iff* the program completes, the file is closed
automatically), it is a good idea to free resources as soon as possible.

<http://php.net/file_get_contents>
<http://php.net/fclose>

> $arr = unserialize($buf);
> foreach ($arr as &$o) {
> print $o->image->name;
> print $o->caption;

This will output the values without delimiter, which is probably not what
you want.

> flush();

This slows down the output and should be unnecessary unless you want output
in real-time.

<http://php.net/flush>

> }
> ?>

This line should be removed if nothing follows, in order to prevent unwanted
output.

<http://php.net/manual/en/language.basic-syntax.phptags.php>

> also:
>
> […]
> printf("%s : %s\n", $o->image->name, $o->caption);

Much better.

> […]
>
> but nothing get printed :-(

Insert

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);

as first statements in your program, and run it again. Since you should not
do experimental work on a remote production system, these settings should be
in your (local) php.ini.

<http://php.net/error_reporting>
<http://php.net/ini_set>

> […]
> --

Be careful not to use lines containing only “-- ” as separators between
prose and code/output in a posting; they are reserved for signature
delimiters. (Fortunately, you or Google Groups – which otherwise is very
buggy – have omitted the space here, so what followed was not truncated by
my newsreader on following up.)

> Array
> (
> [0] => __PHP_Incomplete_Class Object
> (
> [__PHP_Incomplete_Class_Name] => AlbumItem
> [image] => __PHP_Incomplete_Class Object
> (

What *exactly* is this the output of?


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom(at)94(dot)75(dot)214(dot)39>
Re: accessing nested unknown unserialized objects [message #183642 is a reply to message #183638] Tue, 05 November 2013 13:12 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 11/4/2013 3:37 PM, catseye(dot)chandra(at)gmail(dot)com wrote:
> Hello PHP users,
>
> I'm currently fiddling with phpgallery 1.x import/tweaking, and by using unserialize got access to an album metadata.
>
> unserialize gives a big array, with nested objects as each elt.
>
> I cannot find the right way to wright the accessor to two fields of real interest :
>
> $this->image->name
>
> and
>
> $this->caption
>
>
> for now I got :
>
> <?
> $fh = fopen("photos.dat", "r");
> $buf = fread($fh, 1024000);
> $arr = unserialize($buf);
> foreach ($arr as &$o) {
> print $o->image->name;
> print $o->caption;
> flush();
> }
> ?>
>
> also:
>
> <?
> $fh = fopen("photos.dat", "r");
> $buf = fread($fh, 1024000);
> $arr = unserialize($buf);
> foreach ($arr as &$o) {
> //print_r($o);
> printf("%s : %s\n", $o->image->name, $o->caption);
> flush();
> };
> ?>
>
> but nothing get printed :-(
>
> Thanks for any help - I'm a beginner.
>
> --
>
> Array
> (
> [0] => __PHP_Incomplete_Class Object
> (
> [__PHP_Incomplete_Class_Name] => AlbumItem
> [image] => __PHP_Incomplete_Class Object
> (
> [__PHP_Incomplete_Class_Name] => Image
> [name] => aaa
> [type] => jpg
> [width] => 700
> [height] => 525
> [resizedName] => aaa.sized
> [thumb_x] =>
> [thumb_y] =>
> [thumb_width] =>
> [thumb_height] =>
> [raw_width] => 1024
> [raw_height] => 768
> [version] => 38
> )
> [thumbnail] => __PHP_Incomplete_Class Object
> (
> [__PHP_Incomplete_Class_Name] => Image
> [name] => aaa.thumb
> [type] => jpg
> [width] => 210
> [height] => 158
> [resizedName] =>
> [thumb_x] =>
> [thumb_y] =>
> [thumb_width] =>
> [thumb_height] =>
> [raw_width] => 210
> [raw_height] => 158
> [version] => 38
> )
> [preview] =>
> [caption] => Gymnocalycium saglione - juin 01
> [hidden] =>
> [highlight] => 1
> [highlightImage] => __PHP_Incomplete_Class Object
> (
> [__PHP_Incomplete_Class_Name] => Image
> [name] => aaa.highlight
> [type] => jpg
> [width] => 200
> [height] => 150
> [resizedName] =>
> [thumb_x] =>
> [thumb_y] =>
> [thumb_width] =>
> [thumb_height] =>
> [raw_width] => 200
> [raw_height] => 150
> [version] => 38
> )
> [isAlbumName] =>
> [clicks] => 4659
> [keywords] =>
> [comments] =>
> [uploadDate] => 994366657
> [itemCaptureDate] => 992529433
> [exifData] => Array
> (
> [File size] => 160119 bytes
> [File date] => 2004:12:29 22:25:11
> [Camera make] => NIKON
> [Camera model] => E880
> [Date/Time] => 2001:06:14 16:37:13
> [Resolution] => 1024 x 768
> [Flash used] => No
> [Focal length] => 13.9mm
> [Exposure time] => 0.0080 s (1/125)
> [Aperture] => f/9.4
> [ISO equiv.] => 100
> [Metering Mode] => matrix
> [Exposure] => program (auto)
> )
>
> [owner] => 988373499_1755202938
> [extraFields] => Array
> (
> )
> [rank] => 0
> [version] => 38
> [emailMe] => Array
> (
> )
>
> [imageAreas] =>
> )
>

$this is only valid in a class member function. I'm not sure which php
gallery script you're using (there are several of them with similar
names), but unless you've created a class with the above information (or
derived your own class from one with the above information public or
protected), it won't work.

But you didn't give enough of your code for us to provide any real help.

A couple of suggestions: First, on your development system, turn on all
error reporting and display the errors. In your php.ini file, you
should have:

error_reporting = E_ALL
display_errors = on

(You should have display_errors = off in your production system for
security reasons).

Second, if you're still having problems, please post enough code so we
can help you.

P.S. Ignore "Pointed Head". He's just a troll who jumps on anyone who
doesn't follow HIS rules of netiquette. There is no requirement here to
use a real name (although many of us do).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: checking for audio playing ???
Next Topic: detecting a file in use
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 14:14:14 GMT 2024

Total time taken to generate the page: 0.03422 seconds