Re: Re: Strange PHP5 message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, Jason,

Thanks a lot for suggestion. Does it mean that I have tried to serialize some object (like adodb db object)? How I can eliminate this? I really cannot find where this object or whatever else is going to be serailized. The problematic line of code just serialized an array.


On Mar 16, 2005, at 18:30, Jason Barnett wrote:

Andrei Verovski wrote:
...
Notice: serialize() [function.serialize]: __sleep should return an array
only containing the names of instance-variables to serialize. in
ANVphpApp.php on line 840



Anyone knows what is the problem?

Exactly what the notice says ;) basically __sleep is used so that you can prevent certain properties (file pointers, db connections, objects, etc.) from being serialized.

<?php

session_start();
error_reporting(E_ALL);

class Dummy {
  public    $s1  = 'I am a test string';
  protected $s2  = 'I am the protected string';
  private   $_s3 = 'I am the private string';
  var       $a1  = array('testing', 1, 2, 3);
  static    $i1  = 0;

  function __sleep() {
    $i = self::$i1++;
    echo "Oops, I forgot everything!  $i\n";
    return array();
  }
}

class hasMemory extends Dummy {

  private $_fp = NULL;

  function __construct() {
    $this->_fp = fopen('/path/to/some/file', 'r');
  }

  function __sleep() {
    $props_to_save = array('s1', 's2', 'a1');
    echo "I know about the following properties:\n";
    print_r($props_to_save);
    return $props_to_save;
  }
}

$_SESSION['obj1']    = new Dummy();
$_SESSION['obj2']    = new hasMemory();
$_SESSION['string']  = '123abcdefg!';
$_SESSION['integer'] = 1;
$_SESSION['float']   = .1234;
$_SESSION['double']  = .1234567890123456;
$_SESSION['bool']    = TRUE;

foreach ($_SESSION as $key => $value) {
  echo "$key: ";
  var_dump(serialize($value));
}

?>

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html? name=PHP&submitform=Find+search+plugins



********************************************* * Best Regards --- Andrei Verovski * * Personal Home Page * http://snow.prohosting.com/guru4mac/ * Mac, Linux, DTP, Development, IT WEB Site *********************************************


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux