Bir dize olarak sınıfın sadece adı ile erişim sınıfı

1 Cevap php

Ben sınıf fonksiyonunu dedi geçirilmeden, sadece dize adı ile bir işlevi zaten başlatılmış sınıfını kullanmak çalışılıyor.

Örnek:

class art{  
    var $moduleInfo = "Hello World";  
}

$art = new Art;

getModuleInfo("art");

 function getModuleInfo($moduleName){
   //I know I need something to happen right here.  I don't want to reinitialize the class since it has already been done.  I would just like to make it accessible within this function.

   echo $moduleName->moduleInfo;
}

Yardımın için teşekkürler!

1 Cevap

Parametre olarak fonksiyon içine nesnenin kendisini geçmek.

class art{  
    var $moduleInfo = "Hello World";  
}

function getModuleInfo($moduleName){
   //I know I need something to happen right here.  I don't want to reinitialize the class since it has already been done.  I would just like to make it accessible within this function.

   echo $moduleName->moduleInfo;
}

$art = new Art;

getModuleInfo($art);