<?php

/**
*
*/
/*class lantian
{
public $name;
public $age;
private $money;
public $c;
function __construct($name, $arg = '', $money)
{
$this->name = $name;
$this->age = $arg;
$this->money = $money;
} function __isset($var)
{
//设置可以在外面检验的变量
$array = array('name', 'age');
if (in_array($var, $array)) {
// return isset($this->money);
echo $var . "属性存在,他的值是:" . $this->$var;
} elseif (in_array($var, array_keys(get_object_vars($this)))) {
echo "变量不允许外部检测";
return;
} else {
echo "属性不存在";
}
}
//利用魔术:__unset()可以删除私有的属性
function __unset($c)
{
if ($c=='age'){
unset($this->$c);
echo "删除属性{$c}成功";
}else{
echo "不允许删除属性{$c}";
}
}
function get_money(){
echo $this->money;
}
} $lisi = new lantian("李四", 22, 5500); //isset($lisi->name); //获取当前的页码
//echo isset($_GET['page'])?$_GET['page']:1;
$lisi->c=200;
//echo $lisi->c;
unset($lisi->age);
//echo $lisi->get_money();*/ /*$array1=array('php','html','mysql');
$str=serialize($array1);//serialize() 产生一个可存储的值的表示。序列化数据
$array2=unserialize($str);//unserialize() 从已存储的表示中创建 PHP 的值。反序列化
print_r($array2);*/ /*class db{
private $host;
private $user;
private $pwd;
private $dbname;
function __construct($host,$user,$pwd,$dbname)
{
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->dbname=$dbname;
$this->db();
}
function db(){
$mysqli=new mysqli($this->host,$this->user,$this->pwd,$this->dbname);
}
function select(){
$sql="SELECT cate_id,cate_name FROM blog_category";
$result=$this->mysqli->query($sql);
while ($row=$result->fetch_assoc()){
$rows[]=$row;
}
print_r($rows);
}
//反序列化魔术函数
function __wakeup()
{
$this->db();
}
}
session_start(); //打开session();
$chanel=new db('localhost','root','','blog');
//$chanel->select();
//保存查找的内容,进行序列化,在别的页面进行调用:
//$chanel_obj=serialize($chanel);
//var_dump($chanel_obj); $_SESSION['chanel_obj']=serialize($chanel); //保存序列化之后的数据到session中。
echo serialize($chanel);*/ //
class ren{
private $name;
private $age;
function __construct($name,$age)
{
$this->name=$name;
$this->age=$age;
}
function show(){
echo "姓名是:{$this->name} 年龄是:{$this->age}";
}
//魔术方法:__sleep()指定序列化的属性
function __sleep()
{
//return array('name','age'); //获取类的属性:
print_r(array_keys(get_object_vars($this)));//get_object_vars()获取对象的变量属性:
}
}
$zao=new ren('赵六',22);
echo serialize($zao);

  

<?php
/**
*/
session_start();
include '14.php';
$channel_obj=unserialize($_SESSION['channel_obj']);
$channel_obj->select();

  

014对象——对象 __isset __unset __sleep __wakeup的更多相关文章

  1. PHP中的魔术方法总结 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep, __wakeup, __toStr

    PHP中的魔术方法总结 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep ...

  2. php对象: __clone, __toString, __call,__isset, __unset, __sleep, __wakeup,

    __clone: 克隆对象,自动完成操作   clone()  __toString:  return返回字符串  __call: 当调用不存在的函数时,自动执行该方法,并返回相关值 __isset: ...

  3. PHP中的魔术方法:__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep, __wakeup, __toString, __set_state, __clone and __autoload

    1.__get.__set 这两个方法是为在类和他们的父类中没有声明的属性而设计的: __get( $property ) 当调用一个未定义的属性时访问此方法: __set( $property, $ ...

  4. PHP中的魔术方法总结:__construct,__destruct ,__call,__callStatic,__get,__set,__isset, __unset ,__sleep,__wakeup,__toString,__set_state,__clone,__autoload

    1.__get.__set这两个方法是为在类和他们的父类中没有声明的属性而设计的__get( $property ) 当调用一个未定义的属性时访问此方法__set( $property, $value ...

  5. PHP中的魔术方法总结 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep

    PHP中的魔术方法总结 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep ...

  6. php __set() __get() __isset() __unset()四个方法的应用

    一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取 和赋值操作是非常频繁的,因此在PHP5 中,预定义了两个函数“__get()”和“__set()”来获 取和赋值其 ...

  7. [PHP] 魔术方法__get __set __sleep __wakeup的实际使用

    1.__get __set是在给不可访问属性赋值和读取时,调用 2.__sleep 是在序列化对象的时候调用 3.__wakeup是在反序列化对象的时候调用 4.可以在序列化对象的时候 , 只序列化指 ...

  8. PHP中面相对象对象的知识点整理

    面向对象 万物皆对象,将构成问题的事务分解到各个对象上,建立对象的目的不是为了完成一个工作,而是为了描述某个事务在解决问题中的行为,更符合人的思维习惯,代码重用性高,可扩展性. ___________ ...

  9. json 字符串转换成对象,对象转换成json字符串

    json   字符串转换成对象,对象转换成json字符串 前端: 方法一: parseJSON方法:   [注意jquery版本问题] var str = '{"name":&qu ...

随机推荐

  1. django博客项目11

    .....................

  2. pip安装lxml报错 Fatal error in launcher: Unable to create process using '"c:\users\administrator\appdata\local\programs\python\python36\python.exe" "C:\Users\Administrator\AppData\L

    pip install lxml 安装报错 E:\apollo\spider_code>Fatal error in launcher: Unable to create process usi ...

  3. Django - 回顾(2)- 中介模型

    一.中介模型 我们之前学习图书管理系统时,设计了Publish.Book.Author.AuthorDetail这样几张表,其中Book表和Author表是多对多关系,处理类似这样简单的多对多关系时, ...

  4. 海报工厂之(一)android 如何给图片添加水印和文字

    在Android中如何给图片添加水印,下面截取了部分核心代码,仅供参考: /**      * 获取图片缩小的图片      * @param src      * @return      */   ...

  5. 0502-Hystrix保护应用-简介,使用,健康指标等

    一.概述 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_circuit_ ...

  6. python删除目录下七天前创建的文件

    #coding=utf-8 import os import time import datetime def deleteOutdateFiles(path): """ ...

  7. HDU4223:Dynamic Programming?(简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4223 求连续子序列和的最小绝对值,水题. #include <iostream> #inclu ...

  8. c++ 模板 不能 分离编译

    C++Template头文件和定义分开编译的问题 (1) // Foo.htemplate<typename T>class Foo{public:void f();}; // Foo.c ...

  9. webservice -- cxf客户端调用axis2服务端

    背景: 有个项目, 需要由第三方提供用户信息, 实现用户同步操作, 对方给提供webservice接口(axis2实现)并也使用axis2作主客户端调用我方提供的webservice接口 起初, 由于 ...

  10. Redis整合Spring实现缓存

    一.Redis介绍 什么是Redis? redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...