Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 20:51 Go to next message
Eclipse UserFriend
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 #24761 is a reply to message #24723] Thu, 31 May 2007 07:01 Go to previous messageGo to next message
Michael Spector is currently offline Michael SpectorFriend
Messages: 110
Registered: July 2009
Senior Member

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 #24932 is a reply to message #24761] Fri, 01 June 2007 17:04 Go to previous messageGo to next message
Eclipse UserFriend
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 10:01 Go to previous messageGo to next message
Christian Müller is currently offline Christian MüllerFriend
Messages: 9
Registered: July 2009
Junior Member
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 #25097 is a reply to message #25016] Sun, 03 June 2007 07:36 Go to previous messageGo to next message
Michael Spector is currently offline Michael SpectorFriend
Messages: 110
Registered: July 2009
Senior Member

>
> 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.
Re: Unknown method, but no syntax error [message #25386 is a reply to message #25097] Tue, 05 June 2007 00:04 Go to previous message
Eclipse UserFriend
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.
>
>
Previous Topic:Update check problems
Next Topic:Closing Brackets
Goto Forum:
  


Current Time: Mon Sep 23 13:27:55 GMT 2024

Powered by FUDForum. Page generated in 0.03741 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top