導航:首頁 > 編程語言 > 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相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:758
蘋果郵件無法連接伺服器地址 瀏覽:963
phpffmpeg轉碼 瀏覽:672
長沙好玩的解壓項目 瀏覽:145
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:486
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:383
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:350
風翼app為什麼進不去了 瀏覽:779
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:151
伊克塞爾文檔怎麼進行加密 瀏覽:893
app轉賬是什麼 瀏覽:163