interface demo {
const NAME = "常量对象属性";
function myfun1(); //抽象方法
function myfun2(); //抽象方法,不用具体写入逻辑
}
<?php
interface Cinema
{
const film = '加勒比海盗';
public function show();
}
class Order implements Cinema
{
public function show()
{
echo "影院 接口开放了<br>";
}
}
$face = new Order();
echo $face->show();
echo Cinema::film;
<?php
interface Cinema
{
public function show(Order $show,$num);
}
// 显示正常
class Order implements Cinema
{
public $number='0011排';
public function show(Order $show,$num)
{
echo $show->number.$num;
}
}
$face= new Order();
$face->show(new Order,$num='3人');//输出 0011排3人
<?php
interface Cinema
{
public function show();
}
interface Cinema1 extends Cinema
{
public function show1(Order1 $object,$num);
}
class Order implements Cinema1
{
public function show()
{
echo "准备就绪<br>";
}
public function show1(Order1 $object,$num)
{
//var_dump($object);
echo $object->number."$num<br>";
}
}
class Order1
{
public $number="0012排";
function fun(){
echo ' =================';
}
}
$show = new Order1;
$show->fun();
$test = new Order();
$test->show();
$test->show1($show,$num='6人');
// 输出 ===============准备就绪0012排6人
<?php
interface demo {
const NAME = "电影名称";
function fun1();
function fun2();
}
interface demo2 {
function fun3();
function fun4();
}
interface demo3 {
const TEST = "这里是测试Test";
function fun5();
}
class MyDemo implements demo, demo2 {
function fun1() {
echo "你好";
}
function fun2() {
echo "----------";
}
function fun3() {
echo "我也好<br />";
}
function fun4() {
echo "大家都好<br />";
}
}
class YourDemo extends MyDemo implements demo3 {
function fun5() {
echo "继承类后引用接口";
}
}
$p = new YourDemo;
$p->fun1();
$p->fun2();
$p->fun3();
$p->fun4();
$p->fun5();
<?php
//定义接口
interface User{
function getDiscount();
function getUserType();
}
class VipUser implements User{ //VIP用户 接口实现
private $discount = 0.8; // VIP 用户折扣系数
function getDiscount() {
return $this->discount;
}
function getUserType() {
return "VIP用户";
}
}
class Goods{
var $price = 88;
var $vc;
function run(User $vc){ //定义 User 接口类型参数,这时并不知道是什么用户
$this->vc = $vc;
$discount = $this->vc->getDiscount();
$usertype = $this->vc->getUserType();
echo $usertype."商品价格:".$this->price*$discount;
}
}
$display = new Goods();
$display ->run(new VipUser); //VIP用户商品价格:70.4
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有