導航:首頁 > 編程語言 > phpgetmethods

phpgetmethods

發布時間:2022-12-15 14:25:12

A. php中的對象分為哪兩種

得到一個對象的類型,使用gettype()函數:
<?php
echo gettype(1); // 輸出integer
echo gettype(array()); // 輸出array
得到一個對象是哪個類的實例,使用get_class()函數:
<?php
$o = new stdClass();
echo get_class(); // 輸出stdClass

得到一個類或對象的方法和屬性,要使用反射:
<?php
class MyClass {
public $var;
public function foo() {}
}
$ref = new ReflectionClass('MyClass');
$ref->getProperties(); // 會返回一組對象,用法參考PHP手冊
$ref->getMethods(); // 會返回一組對象,用法參考PHP手冊

$obj = new MyClass();
$ref = new ReflectionObject($obj);
$ref->getProperties();
$ref->getMethods();

B. php中怎麼使用ReflectionClass的getMethods方法

你的這個問題完全可以到後盾人那裡解決,那裡有很多相關的視頻教學,我也在那裡學習

C. php怎麼返回類的所有常量屬性

PHP獲取類中常量,屬性,及方法列表的方法

$r=newReflectionClass($this);
Zend_Debug::mp($r->getConstants(),"Constants");
Zend_Debug::mp($r->getProperties(),"Properties");
Zend_Debug::mp($r->getMethods(),"Methods");

D. php 中如何得到一個對象的類型

得到一個對象的類型,使用gettype()函數:

<?php
echogettype(1);//輸出integer
echogettype(array());//輸出array


得到一個對象是哪個類的實例,使用get_class()函數:

<?php
$o=newstdClass();
echoget_class();//輸出stdClass


得到一個類或對象的方法和屬性,要使用反射:

<?php
classMyClass{
public$var;
publicfunctionfoo(){}
}
$ref=newReflectionClass('MyClass');
$ref->getProperties();//會返回一組對象,用法參考PHP手冊
$ref->getMethods();//會返回一組對象,用法參考PHP手冊

$obj=newMyClass();
$ref=newReflectionObject($obj);
$ref->getProperties();
$ref->getMethods();

E. php中怎麼用ReflectionClass中的方法獲取類信息

$class = new ReflectionClass('ClassName');
//獲取ClassName類的屬性
$class->getProperties()
//獲取ClassName類的方法
$class->getMethods()

F. php有沒有什麼函數可以獲取一個方法中的參數名和參數類型的

/**
*獲取一個函數的依賴
*@paramstring|callable$func
*@paramarray$param調用方法時所需參數形參名就是key值
*@returnarray返回方法調用所需依賴
*/
functiongetFucntionParameter($func,$param=[]){
if(!is_array($param)){
$param=[$param];
}
$ReflectionFunc=newReflectionFunction($func);
$depend=array();
foreach($ReflectionFunc->getParameters()as$value){
if(isset($param[$value->name])){
$depend[]=$param[$value->name];
}elseif($value->isDefaultValueAvailable()){
$depend[]=$value->getDefaultValue();
}else{
$tmp=$value->getClass();
if(is_null($tmp)){
thrownewException("{$class}");
}
$depend[]=$this->get($tmp->getName());
}
}
return$depend;
}


functiontest($a,$b=20){
echo$a,',',$b;
}

$depend=getFucntionParameter('test',['a'=>30,'b'=>40]);

call_user_func_array('test',$depend);//30,40

上面的函數是我開發的框架的容器的方法。

php提供了很完整的反射機制。不但可以反射函數,還可以反射方法,反射類構造函數。

G. php中怎麼使用ReflectionClass的getMethods方法

$class = new ReflectionClass('ClassName'); //獲取ClassName類的屬性 $class->getPropert

閱讀全文

與phpgetmethods相關的資料

熱點內容
phpmysqlpdomysqli 瀏覽:802
php修改sql語句 瀏覽:714
android有道api 瀏覽:381
撓耳營水表用的什麼app 瀏覽:49
戰錘40kpdf 瀏覽:375
java判斷字元串是漢字 瀏覽:462
2017初級教材pdf 瀏覽:451
松下空調壓縮機品牌 瀏覽:817
python復選框 瀏覽:746
反詐中心app是什麼時候出來的 瀏覽:586
魔獸世界需要什麼伺服器地址 瀏覽:189
啥是單片機休眠 瀏覽:104
什麼音樂app最好 瀏覽:927
牙膏自製解壓神器 瀏覽:329
卸載linuxwps 瀏覽:228
threadjavarunnable 瀏覽:360
一元線性回歸計演算法 瀏覽:950
刷寶app是什麼鬼 瀏覽:744
linux動態載入模塊 瀏覽:25
javamd5工具類 瀏覽:76