PHP-面向对象(方法)

1.6 方法

方法的本质就是函数

<?php
class Student {
	//定义方法
	public function show() {
		echo '这是show方法<br>';
	}
	//public可以省略,如果省略,默认就是public
	function test() {
		echo '这是test方法<br>';
	}
}
$stu=new Student;
$stu->show();	//调用方法
$stu->test();

多学一招:

1、方法前面public是可以省略的,如果省略,默认就是public的。

2、属性前面的public不能省略

发布了1891 篇原创文章 · 获赞 2009 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/105138671
今日推荐