首页 > Web开发 > 详细

PHP对象继承

时间:2019-11-14 14:18:59      阅读:82      评论:0      收藏:0      [点我收藏+]

PHP对象继承
<?php

class foo
{
public function printItem($string)
{
echo ‘Foo: ‘ . $string . PHP_EOL;
}

public function printPHP()
{
echo ‘PHP is great.‘ . PHP_EOL;
}
}

class bar extends foo
{
public function printItem($string)
{
echo ‘Bar: ‘ . $string . PHP_EOL;
}
}

$foo = new foo();
$bar = new bar();
$foo->printItem(‘baz‘); // Output: ‘Foo: baz‘
$foo->printPHP(); // Output: ‘PHP is great‘
$bar->printItem(‘baz‘); // Output: ‘Bar: baz‘
$bar->printPHP(); // Output: ‘PHP is great‘

?>

PHP对象继承

原文:https://www.cnblogs.com/newmiracle/p/11856253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!