PHP7.27: object
2018-08-13 07:49:12来源:博客园 阅读 ()
<!doctype html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="utf-8"> <title>object 对象</title> <meta name="keywords" content="geovindu"> <meta name="description" content="涂聚文"> </head> <body> <?php // object class User { public $username,$password; function getName() { return $this->username; } function getPassword() { return $this->password; } function Save() { echo("保存成功!"); } } // UserDesc 继承 User类 class UserDesc extends User { public $realname,$email,$birthday; function getRealname() { return $this->realname; } function getEmail() { return $this->email; } function getBirthday() { return $this->birthday; } } function getMillisecond() { list($s1,$s2) = explode(' ', microtime()); return (float)sprintf('%.0f', (floatval($s1)+floatval($s2)) * 1000); } $object=new User; print_r($object);echo("<br/>"); $object->username="geovindu"; // $object->password="888888";// 赋值 print_r($object);echo("<br/>"); $object->Save() ;//显示文字 echo("姓名:".$object->getName()); //显示对象的name值 echo("密码:".$object->getPassword()); $object2=new UserDesc; $object2->birthday=date('Y-m-d H:i:s'); $object2->email='geovindu@163.com'; $object2->realname='涂聚文'; $object2->username='geovindu'; $object2->password='8888'; print_r($object2);echo("<br/>"); // class Collection implements ArrayAccess,IteratorAggregate { public $objectArray = Array(); //**these are the required iterator functions function offsetExists($offset) { if(isset($this->objectArray[$offset])) return TRUE; else return FALSE; } function & offsetGet($offset) { if ($this->offsetExists($offset)) return $this->objectArray[$offset]; else return (false); } function offsetSet($offset, $value) { if ($offset) $this->objectArray[$offset] = $value; else $this->objectArray[] = $value; } function offsetUnset($offset) { unset ($this->objectArray[$offset]); } function & getIterator() { return new ArrayIterator($this->objectArray); } //**end required iterator functions public function doSomething() { echo "I'm doing something"; } } // class CustomContact { protected $name = NULL; protected $tel=null; public function set_name($name) { $this->name = $name; } public function get_name() { return ($this->name); } public function settel($tel) { $this->tel=$tel; } public function gettel() { return ($this->tel); } } // $bob = new Collection(); $bob->doSomething(); $du[]=new CustomContact(); $du[5]=new CustomContact(); $du[0]->set_name("geovindu"); $du[0]->settel("13824350518"); $du[5]->set_name("sibodu"); $du[5]->settel("075582397507"); echo("<br/>"); $num=1; foreach ($du as $aContact) { echo("序号:".$num."<br/>"); echo("姓名:".$aContact->get_name() . "\r\n<br/>"); echo("电话:".$aContact->gettel() . "\r\n<br/>"); $num=$num+1; } $arry =new ArrayObject($du); print_r($arry); // 显示 foreach($arry as $obj) { echo "姓名:" . $obj->get_name(); echo "电话:". $obj->gettel(); } ?> </body> </html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:php intval
- PHP空对象 空数组 2019-07-23
- JSON_FORCE_OBJECT 数字索引数组 强转对象 2018-12-27
- PHP7.27: pdf 2018-09-01
- PHP7.27: Cookie and Session 2018-08-26
- PHP7.27: MySqlhelper class 2018-08-14
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash