PDA

View Full Version : وجود یک function در یک class



Game.Dev
شنبه 18 بهمن 1393, 20:48 عصر
سلام خدمت عزیزان. برای اینکه بفهمیم یک function در یک class هستش یا نه باید از چه تابعی استفاده کرد؟ توجه کنید بررسی رو در یکی از function های همون تابع انجام میدیم.
مثال:


class test
{
public function test1()
{
// check if exists function test2
}

private function test2()
{
//
}
}

abbasfisal
شنبه 18 بهمن 1393, 21:09 عصر
http://php.net/manual/en/function.function-exists.php

http://php.net/manual/en/function.method-exists.php

bagherok
شنبه 18 بهمن 1393, 21:21 عصر
<?php

class test{

public function testFunc($name, $arguments=null)
{
//if function exists within this class call it
if (method_exists($this, $name))
{
$this->$name($arguments);
}
else
{
echo('Undefined function call.<hr/>');
}
}


public function fucnc1($arguments)
{
echo 'Output function test :<br/><pre>'.print_r($arguments,true).'</pre>';

}

}

$Ctest=new test();
$Ctest->testFunc('fucnc2');
$Ctest->testFunc('fucnc1',array(0,1,2));