how check method exist |
[eluser]minhbu[/eluser]
i want to check a method exists in my class but i don`t know to used any function ? Help me
[eluser]Colin Williams[/eluser]
[url="http://www.php.net/method_exists"]http://www.php.net/method_exists[/url]
[eluser]minhbu[/eluser]
i don`t know used it. I know to used it in OOP and in codeigniter is not !
[eluser]Colin Williams[/eluser]
I love your response. It's like a puzzle. Here's how you use it (and this has nothing to do with OOP.. it's just a function that says whether the given object has the given method). Code: class Frog {
[eluser]minhbu[/eluser]
ahhhhhhh i have got a problem. $b="lick"; $this->$b; Undefined property: Frog::$b
[eluser]Colin Williams[/eluser]
You actually have many problems with PHP. I suggest reading the PHP manual at php.net or getting a book. But, just to answer this new question, $b is a variable in that scope (which I am assuming is inside a class member function), not a property. Code: $this->b = "lick";
[eluser]Colin Williams[/eluser]
Oh.. and you're right. I absolutely do use the restroom on occasion.
[eluser]minhbu[/eluser]
No i have a controller demo class Demo extends Controller{ function demo() { parent::Controller(); } function index() { $id=$this->uri->segment(3); if(method_exists($this,$id)) $this->$id; else echo "Your method haven`t got"; } function a() { echo "Hello"; } } I have URI http://localhost/demo/index/a but i have a error A PHP Error was encountered Severity: Notice Message: Undefined property: Demo::$id Filename: controllers/demo.php Line Number: 20
[eluser]Colin Williams[/eluser]
You are calling a function, so you need parenthesis Code: function index() |
Welcome Guest, Not a member yet? Register Sign In |