<?php
class Man{
public function one(){
echo 'public ';
}
protected function two(){
echo 'protected';
}
static private function three(){
echo 'private';
}
static function four(){
echo 'static only';
}
}
$man1= new Man();
/**
*静态方法可以通过未实例化的类直接访问或者通过实例化的类访问,通过::或者new Obj()->,
*但是静态属性只能通过类本身访问,实例化的类是不可以访问类的静态属性的
*/
$man1::four();
var_dump(is_callable(array($man1,'one')));// true
var_dump(is_callable(array("Man",'one')));// true
var_dump(is_callable(array("Man",'two')));//false
var_dump(is_callable(array($man1,'three')));//false
// 拼装数组,结合第二个参数(bool)和第三个参数($string)
$methodVariable1=array('Man','one');
$methodVariable2=array('Man','two');
$methodVariable3=array($man1,'three');// 实例化对象也可以
$methodVariable4=array('Man','three');
$methodVariable5=array('Man','four');
var_dump(is_callable($methodVariable1,true,$call_one));// true
var_dump(is_callable($methodVariable2,true, $call_two));//true
var_dump(is_callable($methodVariable3,true, $call_three));//true
// 如果method为public ,is_callbale()为真,如果methond为protected或者private 为假
echo "\n";
var_dump(is_callable($methodVariable1,false));//true
var_dump(is_callable($methodVariable2,true));//true
var_dump(is_callable($methodVariable3,false,$call_four));//false protected在子类父类本类内部访问
var_dump(is_callable($methodVariable4,false,$call_five));//false private只能在内部调用,所以为false
// 静态方法
echo 'call static only',"\n";
var_dump(is_callable($methodVariable5,false,$call_six));// true
echo 'call static only but use new object',"\n";
var_dump(is_callable(array($man1,'four'),false,$cal_seven));// true
//method_exists 只能验证类(或者实例化对象)的某个方法是否存在(不在乎调用问题),不能用实例化后类的检测
if(method_exists($man1, 'one')){
echo 'yes';
}else{
echo 'no ';//
}
if(method_exists('Man', 'two')){
echo 'yes';//
}else{
echo 'no ';
}
echo"\n";
var_dump($call_one);//Man::one
var_dump($call_two);//Man::two
var_dump($call_three);//Man::three
var_dump($call_four);//虽然是false,也可以输出
var_dump($call_five);//虽然是false,也可以输出
var_dump($call_six);//"Man::four"
var_dump($call_seven);//"Man::four"
is_callable