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] ...
随机推荐
- utf-8转gb2312
近日在对一个json串进行转码时,显示中文乱码,原因是json串编码方式为utf-8,而我程序在windows上采用的是多字节编码方式,即采用gb2312编码.这里就存在一个utf-8到gb2312的 ...
- WeexSDK源码分析(iOS)
0.从工作原理谈起 Weex 表面上是一个客户端技术,但实际上它串联起了从本地开发.云端部署到分发的整个链路.开发者首先可在本地像编写 web 页面一样编写一个 app 的界面,然后通过命令行工具将之 ...
- 背水一战 Windows 10 (69) - 控件(控件基类): UIElement - Manipulate 手势处理, 路由事件的注册, 路由事件的冒泡, 命中测试的可见性
[源码下载] 背水一战 Windows 10 (69) - 控件(控件基类): UIElement - Manipulate 手势处理, 路由事件的注册, 路由事件的冒泡, 命中测试的可见性 作者:w ...
- Python自动化编程-树莓派GPIO编程(二)
树莓派我们编程一般都直接用高效的python,针对于GPIO编程,python也是有这一方面的库的,这里最有名也是最常用的就是RPI.GPIO了.这个库是专门为树莓派GPIO编程所设计的,利用它你可以 ...
- 关于Linux MongoDB的安装
前一篇博文讲解了如何安装与配置MongoDB的windows版,本篇博文接着上一篇讲解如何在Linux系统中安装与配置MongoDB,为了演示,我问同事要了它的云服务器用于演示,当然我自己也有,但是已 ...
- Java 大数值类型执行精确计算
简介 如果基本的整数和浮点数精度不能够满足需求,那么可以使用 java.math 包下两个很有用的类:BigInteger 和 BigDecimal.这两个类可以处理包含任意长度数字序列的数值,Big ...
- Mybatis框架二:增删改查
这里是搭建框架和准备数据: http://www.cnblogs.com/xuyiqing/p/8600888.html 实现增删改查功能: 测试类: package junit; import ja ...
- 花了一晚上时间,终于把Python的基本用法归纳好了!
一.内置函数 1. complex([real[,imag]]) 返回一个复数,实部 + 虚部*1j,或者把字符串或者数字转成复数形式. 参数可以是复数表达式,也可以是字符串.当参数是字符串的时候,数 ...
- Servlet-session简介及使用场景
- Jmeter参数化的方法
测试接口时,使用Jmeter在请求中输入参数,若是有多种情况,有多条测试参数,是不是要每个情况逐条输入呢?逐条输入会让人觉得比较麻烦,因此,就有了Jmeter参数化. Jmeter参数化的方法: 用户 ...