php初进一个项目组,使用几个函数帮忙熟悉流程

初进一个项目组的时候,可能对他的框架啊神马不熟悉的。有时候类里又有各种魔术方法的使用,IDE还跳转不过去对象的方法。
这时候很多php内置函数就可以帮上些忙了。

1. instanceof
2. get_class_methods
3. call_user_func_array

4. 更推荐使用php的反射ReflectionClass


比如想知道这个对象是不是这个类的实例,可以使用instanceof $instance instanceof $class;

当想知道这个实例都可以调用的哪些方法的时候,可以使用get_class_methods($instance) 传入这个实例参数,返回这个实例的类(包括父类)的所有方法,以数组返回。

// call_user_func_array(array($foo, "bar"), array("three", "four")) $foo->bar() 这个就直接拷贝了操作手册里的
<?php
function foobar($arg, $arg2) {
echo __FUNCTION__, " got $arg and $arg2 ";
}
class foo {
function bar($arg, $arg2) {
echo __METHOD__, " got $arg and $arg2 ";
}
}


// Call the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two")); // foobar got one and two

// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four")); // foo::bar got three and four
?>

 ====================================================================

php反射  操作手册:函数参考-->变量与类型相关扩展-->反射(反射还有很多相关函数)

class Hi{}

$obj = new Hi();
$reflect = new ReflectionClass($obj);// 创建一个ReflectionClass对象,参数是类名或者类的实例
$methods = $reflect->getMethods();// 通过ReflectionClass对象获取要查询的对象信息,如方法
$props = $reflect->getStaticProperties();// 如属性、静态属性等
print_r($methods);
print_r($props);

 ====================================================================

线上项目,通常会抑制错误。

而开发时,一般希望看到错误。

这两行代码,有用武之地了

// error_reporting(E_ALL);
ini_set('display_errors','On');

原文地址:https://www.cnblogs.com/firstForEver/p/4726234.html