⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 07c08-1.php

📁 介绍PHP5的给类型函数应用
💻 PHP
字号:
<?php// Define a class that will store values for any property it is given.class Data_Holder {    // The data storage array    private $data = array();    // A method to set any variable passed to this object.      // Store it in the array    public function __set($name, $value) {        $this->data[$name] = $value;    }        // A method to return any values that are set:    public function __get($name) {        if (isset($this->data[$name])) { return $this->data[$name]; }    }    // A method that will allow 'isset' to work on these variables    public function __isset($name) {        return isset($this->data[$name]);    }        // Finally a method to allow 'unset' calls to work on these variables    public function __unset($name) {        unset($this->data[$name]);    }}// Create a data holding object & store some data in it:$data = new Data_Holder();$data->name = 'Francesca';// Now echo the value out to see that the __get method is working:echo "<p>The data value of 'name' is {$data->name}</p>";// Now unset the value, and then use isset to ensure that it happened.unset($data->name);echo '<p>The value is ', isset($data->name) ? '' : 'not ', 'set.</p>';?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -