Code: Select all
Class Ab {
Function Ab ($x)
{
$this->AC($x)
}
Function AC ($x)
{
print $x;
}
}
$MainClass = New MainClass;
$MainClass->print = $MainClass::Ab;how can I call the AC function in this stat ??
Moderator: General Moderators
Code: Select all
Class Ab {
Function Ab ($x)
{
$this->AC($x)
}
Function AC ($x)
{
print $x;
}
}
$MainClass = New MainClass;
$MainClass->print = $MainClass::Ab;Code: Select all
<?
class MainClass
{
function AC()
{
return "somethign";
}
}
echo MainClass::AC();
?>Sorry for my bad english.Everah wrote:You're going to have to clarify that a little bit. You are not even remotely coding a singleton class. What is it you are trying to do?
thanks for you help.Burrito wrote:if you're trying to call the method statically, you don't need to call it from the object.
Code: Select all
<? class MainClass { function AC() { return "somethign"; } } echo MainClass::AC(); ?>
Code: Select all
class Something
{
var $burrito ;
function AA()
{
return self::AB() ;
}
function AB()
{
return self::$burrito ;
}
}
$taco = Something::AA() ;Begby wrote:To answer what I think is your first question, what you are doing is calling a static method and from that static method want to call another method of your object. You use the 'self' keyword instead of 'this' like:
Code: Select all
class Something { var $burrito ; function AA() { return self::AB() ; } function AB() { return self::$burrito ; } } $taco = Something::AA() ;