"Method '[methodname]' not found in class"

I'm evaluating the trial version of PhpStorm and am having a problem. I'm getting the following error when I call some, but not all, methods for a class:

[quote]Method '[methodname]' not found in class[/quote]

The strange thing is that this "error" does not show up for some of the methods, only certain ones. The methods are certainly defined and can be run without problems.

Why is this error showing up in the editor?

Thanks for your help.

9 comments
Comment actions Permalink

Hi Nathan,

My car does not start -- why?

I'm sure we will both agree -- we need to have more details before suggesting anything in such situation. Therefore -- please provide such info -- screenshots of the actual message (where it works and where it does not) + some standalone code to reproduce the issue. Also -- what version of PhpStorm do you use (Help | About)?

Quite likely it is a bug in PhpStorm .. or code written in a way that prevents PhpStorm from analysing it properly (e.g. figuring out what methods are available), but code example is required to make such judgement.

0
Comment actions Permalink

Hello,

Sorry to resurrect this thread from the  grave, but I ended up purchasing phpStorm (a GREAT decision on my part, I  love it!) and still have this problem.

Here's an example:

http://img16.imageshack.us/img16/7396/class1n.png

<?php

class class_1
{
    public function __construct()
    {

    }

    public function testFunction()
    {
        echo 'hello world';
    }
}




http://img842.imageshack.us/img842/1291/class2i.png

<?php

include 'class_1.php';


class class_2
{
    public $class1member;

    public function __construct()
    {
        $this->foo();
        $this->bar();
    }

    public function foo()
    {
        $this->class1member = new class_1();
    }

    public function bar()
    {
        $this->class1member->testFunction();
    }
}


I'm kind of a newbie php programmer, so it's very possible that I don't know a trick to make this work correctly.

Appreciate your advice!

0
Comment actions Permalink

Hi there,

The best way is to add proper PHPDoc comment for that class variable, e.g.

/** @var class_1 My special variable (or whatever description you want) */

public $class1member;


Similar idea can be used for function level PHPDoc comment -- it will kill 2 rabbits with one shot: self documentation + hint for IDE with function description, parameter types and return type(s).

Just type /** and then either hit Space (for single line comment) or Enter (or multi-line comment) and PhpStorm will help creating it (the amount of help depends on various conditions: where are you creating it, what "level" that comment is (class/function/field/local var/etc)

You can check other possible PHPDoc tags here: http://www.phpdoc.org/docs/latest/for-users/list-of-tags.html

0
Comment actions Permalink

Wonderful, thank you! I added the @var tag before my objects and the methods are now found!

I tried adding tags before a function, but I'm not sure what is supposed to happen when I do that? I thought maybe the comments would pop up when I put my cursor over a function name, or when typing the function name, but that didn't happen..

Thanks again!

0
Comment actions Permalink

An example:

<?php

/**
* My very special class for a special occasion
*/
class MySpecialClass
{
    /** My special constant, not used anywhere here */
    const MY_CONST = 2;
    
    /**
     * My very special function (I love money)
     *
     * @param float|int $amount Amount to be formatted
     * @param string $currency My first string parameter
     * @param string $extra [optional] My second string parameter which is optional
     * @return string
     */
    public function myMoneyFormat($amount, $currency, $extra = '')
    {
        return strtoupper($currency) . ' ' . number_format($amount, 2, '.', ',') . rtrim(' ' . $extra);
    }
}

If you invoke View | Quick Documentation (Ctrl+Q) when standing over function name, you will see this kind of popup (plus parameter types will be used to validate the correctness of actual parameters passed to this function).

screen01.png

Parameter types will also be used when quick Parameter Info popup is shown (View | Parameter Info (Ctrl+P) -- can be invoked manually when standing inside function parameters list)

P.S.
I suggest checking some well maintained open source project/framework to see how they use PHPDoc comments (Zend Framework, Yii, Symfony2, Swift Mailer etc etc)

0
Comment actions Permalink

Oh my gosh, that is amazing!

You have totally rocked my world :)

Thanks for your help!

0
Comment actions Permalink

I have a related question. I recently have started to use php's SOAPClient class and I'm finding that the methods defined in the WSDL file are not being recognized by PhpStorm. I tried adding:

/** @var SOAPClient */


Before the variable I use to hold the SOAPClient object, but the methods still aren't "found."

In other words, I have something like this:


$this->client = new SOAPClient('url-to.wsdl', array('trace' => 1));
...
$this->client->method(pars);

Where "method" would be highlighted in PhpStorm.

Do you have any suggestions?

0
Comment actions Permalink

As I understand that those "method(s)" are provided by that url-to.wsdl rather than native SOAPClient functions, right?

If so -- then you have 2 possible choices here:

1. Disable warning for unknown methods: Settings | Inspections | PHP | Undefined | Undefined method --> Downgrade severity when __magic methods are present in class

This will simply make such warnings much less visible. Because those "methods" are not part of the SOAPClient class, but actually offered by that remote services (url-to.wsdl), in PHP they got executed/redirected via __call() method of SOAPClient class so it looks like they are part of the actual SOAPClient class.

You will not have any code completion or documentation for such methods in such way -- it will only make warnings about unknown methods almost unnoticeable in PhpStorm.

2. Provide your own stub file that will describe what methods (and what parameters) are expected here.

Stub file is a simple PHP file with proper class/function/constant/etc definitions but without actual code/implementation (which means, all function's bodies are empty) -- that's how all supported classes/functions are done in PhpStorm any way -- Ctrl+Click on SOAPClient in this line ( $this->client = new SOAPClient('url-to.wsdl', array('trace' => 1)); )  or on any other standard supported class/function and you will see what I mean.

So .. create such fake class that will list all methods (with params description if desired, etc) offered by that service, put it anywhere in your project, then use it in your PHPDoc comment, e.g.

/** @var SOAPClient|MyFakeClassForWDSL */


This will tell PhpStorm to look for a method/field in both classes -- this will cover actual SOAPClient "native" functions as well as functionality/methods offered by that remote service (url-to.wsdl).

Such approach will ensure that such remote methods are known to PhpStorm and it will offer code completion (and other documentation for parameters, method description -- if you provide such documentation in appropriate PHPDoc comments, of course).

0
Comment actions Permalink

does anyone has an idea how this could work in my case: http://devnet.jetbrains.com/message/5490727#5490727 ???

0

Please sign in to leave a comment.