Home » Language IDEs » PHP Development Tools (PDT) » Unknown method, but no syntax error
Unknown method, but no syntax error [message #24723] |
Wed, 30 May 2007 16:51  |
Eclipse User |
|
|
|
Originally posted by: andy.schmitt.parthenonsoftware.com
Hi all,
I've got a question about syntax highlighting. When I put a call to a
nonexistent method in my code, the PDT editor does not underline it as
an error. This despite the fact that it knows which methods I have
available and (IMHO) ought to be able to know that the method is not in
that list. PHP itself wouldn't recognize this as a fatal error until it
attempted to make the call, but I think this ought to be caught by the
editor long before putting it out as code. I'm using the latest release
candidate. Am I doing something wrong, or is this just a feature that
hasn't been put in yet? I don't see anything in the FAQ regarding this.
Example:
<?php
class TestClass
{
public function __construct()
{
}
public function testTest($string)
{
echo $string;
}
}
$test = new TestClass();
$test->testSomeInvalidFunction("Hello");
?>
Thanks for your help.
Andy Schmitt
|
|
| |
Re: Unknown method, but no syntax error [message #24932 is a reply to message #24761] |
Fri, 01 June 2007 13:04   |
Eclipse User |
|
|
|
Originally posted by: andy.schmitt.parthenonsoftware.com
Michael, you are, unfortunately, correct. I forgot about __call().
However, I still think it still would be nice to put in a warning to the
developer if he/she is calling an undefined method, which could be
disabled if the developer does go hog-wild with undefined functions and
doesn't want to be bothered.
__call() is a very special case that most developers don't need (if I
know what method I'd be calling, I'd use a function, not a switch within
call). The main argument I see for it is that it allows overloading a
function in a superficially similar way to other OO languages, but I
think the cure is worse than the disease, as using __call almost
certainly increases code complexity in a way that PDT can't handle
nicely (i.e. potentially concealing functions so the Project Explorer
can't see them).
I don't know about anyone else here, but I make stupid mistakes with
undefined functions much more often than I make brilliant coups with
__call(). :) I just wanted to be sure I wasn't missing an existing
feature, or that there was a very good reason not to warn the developer
if he called an undefined function. If this currently isn't a
consideration, I'll write a patch to put it in myself.
Andy
Michael Spector wrote:
> Calling undefined methods is pretty much valid operation in PHP :)
> See
> http://www.hudzilla.org/phpwiki/index.php?title=Magic_functi ons#__call.28.29
> for more details.
>
> "Andy Schmitt" <andy.schmitt@parthenonsoftware.com> wrote in message
> news:f3ko4l$oea$1@build.eclipse.org...
>> Hi all,
>>
>> I've got a question about syntax highlighting. When I put a call to a
>> nonexistent method in my code, the PDT editor does not underline it as an
>> error. This despite the fact that it knows which methods I have available
>> and (IMHO) ought to be able to know that the method is not in that list.
>> PHP itself wouldn't recognize this as a fatal error until it attempted to
>> make the call, but I think this ought to be caught by the editor long
>> before putting it out as code. I'm using the latest release candidate. Am
>> I doing something wrong, or is this just a feature that hasn't been put in
>> yet? I don't see anything in the FAQ regarding this.
>>
>> Example:
>>
>> <?php
>>
>> class TestClass
>> {
>> public function __construct()
>> {
>> }
>>
>> public function testTest($string)
>> {
>> echo $string;
>> }
>> }
>>
>> $test = new TestClass();
>> $test->testSomeInvalidFunction("Hello");
>> ?>
>>
>> Thanks for your help.
>>
>> Andy Schmitt
>
>
|
|
|
Re: Unknown method, but no syntax error [message #25016 is a reply to message #24932] |
Fri, 01 June 2007 06:01   |
Eclipse User |
|
|
|
Andy Schmitt schrieb:
> Michael, you are, unfortunately, correct. I forgot about __call().
Right, but Micheal forogt, that __call has to be implemented. Otherwise
a undefined function simply produced a fatal (but you may have noticed
that already)
>
> However, I still think it still would be nice to put in a warning to the
.....
> if he called an undefined function. If this currently isn't a
> consideration, I'll write a patch to put it in myself.
And i would volunteer to test it ^^
Also offer some suggestions:
- mark undefined functions as Errors
- if the class, has __call() give the function a different highlighting
color and link it's definition to __call
- perhaps show these functions in the outline with a new symbol
Btw. something like this would be quite interessting for undefined
Properties, too ^^
>
> Andy
>
>
> Michael Spector wrote:
>> Calling undefined methods is pretty much valid operation in PHP :)
>> See
>> http://www.hudzilla.org/phpwiki/index.php?title=Magic_functi ons#__call.28.29
>> for more details.
>>
>> "Andy Schmitt" <andy.schmitt@parthenonsoftware.com> wrote in message
>> news:f3ko4l$oea$1@build.eclipse.org...
>>> Hi all,
>>>
>>> I've got a question about syntax highlighting. When I put a call to a
>>> nonexistent method in my code, the PDT editor does not underline it
>>> as an error. This despite the fact that it knows which methods I have
>>> available and (IMHO) ought to be able to know that the method is not
>>> in that list. PHP itself wouldn't recognize this as a fatal error
>>> until it attempted to make the call, but I think this ought to be
>>> caught by the editor long before putting it out as code. I'm using
>>> the latest release candidate. Am I doing something wrong, or is this
>>> just a feature that hasn't been put in yet? I don't see anything in
>>> the FAQ regarding this.
>>>
>>> Example:
>>>
>>> <?php
>>>
>>> class TestClass
>>> {
>>> public function __construct()
>>> {
>>> }
>>>
>>> public function testTest($string)
>>> {
>>> echo $string;
>>> }
>>> }
>>>
>>> $test = new TestClass();
>>> $test->testSomeInvalidFunction("Hello");
>>> ?>
>>>
>>> Thanks for your help.
>>>
>>> Andy Schmitt
>>
>>
|
|
| |
Re: Unknown method, but no syntax error [message #25386 is a reply to message #25097] |
Mon, 04 June 2007 20:04  |
Eclipse User |
|
|
|
Originally posted by: andy.schmitt.parthenonsoftware.com
Voted for it. Thanks for putting it in, Michael.
As for properties, that could be treated as a warning that could be
enabled upon user preference, as I mentioned before for functions. For
my projects I'd definitely want to see if someone was trying to define
an undefined property in a class, but of course there are probably some
projects that use this all the time.
Andy
Michael Spector wrote:
>> Also offer some suggestions:
>> - mark undefined functions as Errors
>> - if the class, has __call() give the function a different highlighting
>> color and link it's definition to __call
>> - perhaps show these functions in the outline with a new symbol
>>
>
> I agree, this might be a great feature.
> I've just added it to the BTS:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=190676
>
>> Btw. something like this would be quite interessting for undefined
>> Properties, too ^^
>>
>
> This case can be problematic, since properties can be defined on the fly:
>
> class A {
> }
>
> $a = new A();
> $a->property = "blabla";
>
> This is valid in PHP.
>
>
|
|
|
Goto Forum:
Current Time: Mon Apr 28 02:43:49 EDT 2025
Powered by FUDForum. Page generated in 0.06681 seconds
|