If: Notice: serialize(): “DIY” returned as member variable from__ The solution of sleep() but do error
<?php
header('content-type:text/html;charset=utf-8');
class SportObject{
protected $type="DIY";
public function getType(){
return $this->type;
}
public function __sleep(){
echo 'Use the serialize() function to save the object to a text file, database, etc. <br>';
return array('type'); //Note here, this should return an array, not return $this on the ebook Of course the paper book is the correct way to write it.
}
public function __wakeup(){
echo 'When this data is needed, use the unserialize() function on the serialized string to convert it back to an object<br>';
}
}
$mybook=new SportObject();
$a=serialize($mybook);
echo 'Serialized string: '. $a."<br>";
$b=unserialize($a);
echo 'Restored member variable.'.$b->getType();
?>
Output results:
Use the serialize() function to save the object, which can be stored in text files, databases, etc.
the serialized string: O: 11: “sportobject”: 1: {s: 7: “* type”; s: 3: “DIY”;}
when the data is needed, use the unserialize() function to operate the serialized string and convert it back to the object
restored member variable: DIY
Read More:
- PHP Error Object of class mysqli could not be converted to string in
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- /www/server/php/56/sbin/php-fpm:error while loading shared libraries:libssl.so.1.0. 0:cannot open shared object file:No such file or directory
- PHP: How to parse MHT file into HTML
- PHP error in Windows: class’ mysqli ‘not found
- PHP parse error: syntax error, unexpected ‘use’
- [PHP]json_encode Chinese JSON_UNESCAPED_UNICODE returns null in php5.3
- [Solved] PHP Error: Warning: file_get_contents(): Failed to enable crypto
- [Solved] PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes
- Mac PHP Fatal error: Class ‘Memcache’ not found
- [Solved] PHP post Datas json_decode Error: 4 JSON_ERROR_SYNTAX
- PHP: The Difference between \Throwable, \Error and \Exception
- [Solved] PHP installation Phalcon expansion error
- Mac: Where is php.ini Location
- How to Hide index.php
- HTML + PHP inline execute JavaScript Error [How to Solve]
- laravel The Process class relies on proc_open, which is not available on your PHP installation.
- Laravel-admin php artisan admin:install error reporting problem solution
- PHP php-config is not installed error in ubuntu 16 [How to Solve]
- [PHP] Solve PHP Call to undefined function ldap_connect()