Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using functions from within the same class

This is probably a really simple question however Google isn't my friend today.

I have something like this but it says call to undefined function

<?php     class myClass{         function doSomething($str){             //Something is done here         }         function doAnother($str){             return doSomething($str);         }     } ?> 
like image 212
Ben Shelock Avatar asked Dec 21 '09 08:12

Ben Shelock


People also ask

How do you call a function inside the same class?

In this program, you have to first make a class name 'CallingMethodsInSameClass' inside which you call the main() method. This main() method is further calling the Method1() and Method2(). Now you can call this as a method definition which is performing a call to another lists of method.

Can you call a function from within it?

Calling a function from within itself is called recursion and the simple answer is, yes.

How can I access a function inside a class in PHP?

You need to call newTest to make the functions declared inside that method “visible” (see Functions within functions). But that are then just normal functions and no methods. Show activity on this post.


1 Answers

Try the following:

return $this->doSomething($str); 
like image 144
Konamiman Avatar answered Sep 28 '22 05:09

Konamiman