开发者

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($st开发者_高级运维r){
            return doSomething($str);
        }
    }
?>


Try the following:

return $this->doSomething($str);


You can try a static call like this:

function doAnother ($str) {
    return self::doSomething($str);
}

Or if you want to make it a dynamic call, you can use $this keyword, thus calling a function of a class instance:

function doAnother ($str) {
    return $this->doSomething($str);
}


Try:

return $this->doSomething($str);

Have a look at this as well: http://php.net/manual/en/language.oop5.php


try:

return $this->doSomething(str);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜