Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11731 > unrolled thread

accessing nested unknown unserialized objects

Started bycatseye.chandra@gmail.com
First post2013-11-04 12:37 -0800
Last post2013-11-05 08:12 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  accessing nested unknown unserialized objects catseye.chandra@gmail.com - 2013-11-04 12:37 -0800
    Re: accessing nested unknown unserialized objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-05 13:11 +0100
    Re: accessing nested unknown unserialized objects Jerry Stuckle <jstucklex@attglobal.net> - 2013-11-05 08:12 -0500

#11731 — accessing nested unknown unserialized objects

Fromcatseye.chandra@gmail.com
Date2013-11-04 12:37 -0800
Subjectaccessing nested unknown unserialized objects
Message-ID<73a48b65-ce17-461c-92a5-d681547aa4c9@googlegroups.com>
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] => 
      )

[toc] | [next] | [standalone]


#11733

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-05 13:11 +0100
Message-ID<11530910.WaAG51LVq5@PointedEars.de>
In reply to#11731
catseye.chandra@gmail.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@94.75.214.39>

[toc] | [prev] | [next] | [standalone]


#11735

FromJerry Stuckle <jstucklex@attglobal.net>
Date2013-11-05 08:12 -0500
Message-ID<l5aqrc$dhm$1@dont-email.me>
In reply to#11731
On 11/4/2013 3:37 PM, catseye.chandra@gmail.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@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web