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的更多相关文章

  1. PHP7.27: MySqlhelper class

    https://github.com/ThingEngineer/PHP-MySQLi-Database-Class https://github.com/wildantea/php-pdo-mysq ...

  2. PHP7.27: connect mysql 5.7 using new mysqli_connect

    <!doctype html> <html> <head> <meta name="viewport" content="wid ...

  3. PHP7.27: connect mysql 5.7 using new mysqli

    <!doctype html> <html> <head> <meta name="viewport" content="wid ...

  4. PHP7.27: pdf

    http://www.fpdf.org/ https://github.com/Setasign/FPDF https://www.ntaso.com/fpdf-and-chinese-charact ...

  5. PHP7.27: Cookie and Session

    <?php // 有的浏览器不支持Cookie,这要考虑的 $cFile="count.txt"; $acctime=time(); if(file_exists($cFil ...

  6. php7.27: export excel from mysql

    https://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php https://github.com/PH ...

  7. [Javascript] Object.assign()

    Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html Object.assign() ca ...

  8. PHP中遍历stdclass object 及 json 总结[中国航天神舟十号以json形式向地面返回数据]

    $test=Array ( [0] => stdClass Object ( [tags] => 最快的车,Bloodhound,SSC [id] => 48326888 11 从网 ...

  9. PHP中遍历stdclass object 及 json

    原文:PHP中遍历stdclass object 及 json (从网上找的模拟实例)需要操作的数据: $test=Array ( [0] => stdClass Object ( [tags] ...

随机推荐

  1. grid布局学习二之子元素(项目)

    /* grid-column-start属性:左边框所在的垂直网格线 grid-column-end属性:右边框所在的垂直网格线 grid-row-start属性:上边框所在的水平网格线 grid-r ...

  2. 一篇入门 -- Git

    一. Git 介绍 Git作为一款分布式的==版本控制==工具,作为一名程序员,是必须要掌握的. 最初由林纳斯·托瓦兹(Linus Torvalds)创作,于2005年以GPL发布.最初目的是为更好地 ...

  3. Android OpenGL ES 开发(N): OpenGL ES 2.0 机型兼容问题整理

    在使用OpenGL ES做开发的时候,发现不是所有机型对OpenGL的代码都兼容的那么好,同样的代码在某些机型上总是会出现问题,但是在其他手机上就是好的.下面是本人总结的OpengGL 兼容问题: 一 ...

  4. EXCEL在改动某几个单元格时隐藏空列

    概述 今天我哥来找我帮他搞下excel表格,本着程序猿对程序无所不能的精神,我爽快的答应了.结果查了半天才搞定.现在记录在此,供自己以后参考,相信对其他人也有用. PS:这几天正在弄博客,马上就要弄完 ...

  5. Shell-9--条件测试

  6. tar与压缩详解

    .gz  gzip   gunzip(gzip -d) .zip .rar .bz2 gzip压缩文件不保留原文件 , 不能压缩目录 gzip   filename.x   用gzip压缩文件 gun ...

  7. 多个git使用的 ssh key共存

    ssh-keygen -t rsa -C "ljkj028@qq.com" 不要一直回车,指定密钥为 id_rsa_ljkj 默认为(id_rsa) 同理 创建其他密钥 打开ssh ...

  8. WebMvcConfigurer

    [传送门]:详解WebMvcConfigurer接口 1. 设置跨域规则 @Configuration public class CrossOriginConfig implements WebMvc ...

  9. Centos6.5安装Python2.7.9

    1. 问题背景 Centos6.5默认自带的python环境是2.6.6,python的一些特性没法使用,所以要对python进行升级,借鉴了网上其他同学的安装教程,但是还是遇到一些坑,不是那木顺利, ...

  10. OC学习5——类和对象

    1.OC是在C语言基础上进行扩展得到的一门面向对象的程序设计语言,它也提供了定义类.成员变量和方法的基本功能.类可以被认为是一种自定义的数据类型,使用它可以定义变量,所有使用类定义的变量都是指针类型的 ...