PHP7.27: object
http://www.devshed.com/c/a/PHP/PHP-Services-Layers-Data-Mappers/
https://stackoverflow.com/questions/1980015/model-mapper-relationship
http://assets.en.oreilly.com/1/event/36/PHP%20Object-Relational%20Mapping%20Libraries%20In%20Action%20Presentation.pdf
https://github.com/marcelgsantos/learning-oop-in-php
https://github.com/domnikl/DesignPatternsPHP/tree/master/Structural/DataMapper
https://www.sitepoint.com/handling-collections-of-aggregate-roots/
https://www.sitepoint.com/integrating-the-data-mappers/
https://github.com/TwisterMW/php-dal-model
http://www.phpdao.com/
<!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>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>接口Creating a Data Abstraction Layer in PHP</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文">
<meta name="author" content="涂聚文">
</head> <body>
<?php
//https://github.com/ADOdb/ADOdb
//https://github.com/AdamB7586/pdo-dbal
//https://github.com/daijulong/generator interface Maxmin{
public function getMax(); public function getMin(); } class msm implements Maxmin{
private $aa=33;
private $bb=66;
//具体实现接口声明的方法
public function getMax()
{
return $this->bb;
} public function getMin()
{
return $this->aa;
} public function getOther(){
return 'geovindu:hi,how are you.';
}
} $msm=new msm();
echo($msm->getMax());
echo("<br/>");
echo($msm->getMin());
echo("<br/>");
echo($msm->getOther()); ?>
</body>
</html>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>多态性</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文">
<meta name="author" content="涂聚文">
</head> <body>
<?php
//定义蔬菜抽象类
abstract class Vegetables{
//抽象方法
abstract function go_Vegetables();
} //马铃薯继承蔬菜类
class Vegetables_potato extends Vegetables{
//重写抽象方法
public function go_Vegetables(){
echo("我是马铃薯");
}
}
//萝卜继承蔬菜类
class Vegetables_radish extends Vegetables{
public function go_Vegetables()
{
echo("我是萝卜");
}
}
//自定义方法根据对象调用不同的方法
function change($obj)
{ if($obj instanceof Vegetables)
{
$obj->go_Vegetables();
}
else
{
echo("输入的参数不是一个对象");
}
} try
{
echo("实例化Vegetables_potato:");
change(new Vegetables_potato());
echo("<br/>");
echo("<br/>");
echo("实例化Vegetables_radish:");
change(new Vegetables_radish());
}
catch(Exception $ex)
{
echo("异常信息:".$ex->getMessage());
}
?>
</body>
</html>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>通过接口实现多态</title>
<meta name="keywords" content="geovindu">
<meta name="description" content="涂聚文">
<meta name="author" content="涂聚文">
</head> <body>
<?php
//定义接口
interface Vegetables{
//定义接口方法
public function go_Vegetables();
} //马铃薯继承蔬菜类
class Vegetables_potato implements Vegetables{
//重写抽象方法
public function go_Vegetables(){
echo("我是马铃薯");
}
}
//萝卜继承蔬菜类
class Vegetables_radish implements Vegetables{
public function go_Vegetables()
{
echo("我是萝卜");
}
}
//自定义方法根据对象调用不同的方法
function change($obj)
{ if($obj instanceof Vegetables)
{
$obj->go_Vegetables();
}
else
{
echo("输入的参数不是一个对象");
}
} try
{
echo("实例化Vegetables_potato:");
change(new Vegetables_potato());
echo("<br/>");
echo("<br/>");
echo("实例化Vegetables_radish:");
change(new Vegetables_radish());
}
catch(Exception $ex)
{
echo("异常信息:".$ex->getMessage());
}
?>
</body>
</html>
PHP7.27: object的更多相关文章
- PHP7.27: MySqlhelper class
https://github.com/ThingEngineer/PHP-MySQLi-Database-Class https://github.com/wildantea/php-pdo-mysq ...
- PHP7.27: connect mysql 5.7 using new mysqli_connect
<!doctype html> <html> <head> <meta name="viewport" content="wid ...
- PHP7.27: connect mysql 5.7 using new mysqli
<!doctype html> <html> <head> <meta name="viewport" content="wid ...
- PHP7.27: pdf
http://www.fpdf.org/ https://github.com/Setasign/FPDF https://www.ntaso.com/fpdf-and-chinese-charact ...
- PHP7.27: Cookie and Session
<?php // 有的浏览器不支持Cookie,这要考虑的 $cFile="count.txt"; $acctime=time(); if(file_exists($cFil ...
- php7.27: export excel from mysql
https://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php https://github.com/PH ...
- [Javascript] Object.assign()
Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html Object.assign() ca ...
- PHP中遍历stdclass object 及 json 总结[中国航天神舟十号以json形式向地面返回数据]
$test=Array ( [0] => stdClass Object ( [tags] => 最快的车,Bloodhound,SSC [id] => 48326888 11 从网 ...
- PHP中遍历stdclass object 及 json
原文:PHP中遍历stdclass object 及 json (从网上找的模拟实例)需要操作的数据: $test=Array ( [0] => stdClass Object ( [tags] ...
随机推荐
- three.js 一幅图片多个精灵
https://blog.csdn.net/zhulx_sz/article/details/79105359 核心代码 // 把一幅外部图片中包含的5种精灵存入一个精灵材质数组 var sprite ...
- DLL补丁劫持制作
DLL: 由于输入表中只包含 DLL 名而没有它的路径名,因此加载程序必须在磁盘上搜索 DLL 文件.首先会尝试从当前程序所在的目录加载 DLL,如果没找到,则在Windows 系统目录中查找,最后是 ...
- CTFcrackTools-V3 - 一款旨在帮助 CTFer 在 CTF 中发挥作用的一个框架
CTFcrackTools-V3 CTFcrackTools重置版 作者:米斯特安全-林晨.摇摆.奶权 米斯特安全团队首页:http://www.hi-ourlife.com/ 部分插件来源:希望团队 ...
- 第30节:Java基础-内部类
内部类 // 外部类 class Demo{ private int num = 3; // 定义内部类 class Int{ void show(){ System.out.println(&quo ...
- 浅谈css3长度单位rem,以及移动端布局技巧
rem是什么? rem是css3中新增加的一个单位属性(font size of the root element),根据页面的根节点的字体大小进行转变的单位.root!!!!!!!!!根节点,也就是 ...
- spring框架学习笔记1:搭建测试
Spring框架介绍: Spring框架涵盖了web.service.dao三层,本身是一个存放对象的容器 形象来说:Spring是项目中对象管家 Spring框架的两大核心思想:控制反转(IOC). ...
- callback vs async.js vs promise vs async / await
需求: A.依次读取 A|B|C 三个文件,如果有失败,则立即终止. B.同时读取 A|B|C 三个文件,如果有失败,则立即终止. 一.callback 需求A: let read = functio ...
- Django创建和配置文件
首先我们随便找一个文件 shift+鼠标右键 点击打开 Powershell 窗口 然后输入命令 django-admin startproject 项目名字 输入cd day 进入这个项目下 ...
- Linux - 常用网络操作
001 - Linux CentOS网络配置 CentOS---网络配置详解 002 - Linux查看端口状态 检测本机8080端口状态:netstat –apn | grep 8080 检测192 ...
- code128 C语言实现
https://blog.csdn.net/walk_ing/article/details/52712641 参考链接 1,具有A.B.C三种不同的编码类型,可提供标准ASCII中128个字元(字元 ...