You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "negora (via GitHub)" <gi...@apache.org> on 2025/06/10 11:19:01 UTC

[D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

GitHub user negora created a discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

Hi:

I've created a PHP project from scratch, in NetBeans 26. I'm editing a single PHP file (a very simple one), and I was wondering if a call to an undefined function shouldn't trigger an error in the editor (or a warning at least). For example, consider this piece of code:

```php
<?php
foo ();
```

I understand that `foo()` may or may not exist in the global space but, Doesn't Netbeans scan the whole project to discover which declarations are made in each space?

Thank you.


GitHub link: https://github.com/apache/netbeans/discussions/8573

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
GitHub user matthiasblaesing added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

You assume, that NetBeans "knows" about your runtime environment, but that is not the case. You can install extensions outside your project and these can make global function available to your code. So there is a high risk to cause false positives for such warnings.

GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13422974

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
GitHub user junichi11 added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

As Tomas wrote, there may be a performance problem. There may be other special cases, such as Matthias's example. (e.g. on frameworks)
So, I don't suppose this is easy...

GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13498419

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "negora (via GitHub)" <gi...@apache.org>.
GitHub user negora added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

@matthiasblaesing Good point. To be honest, I didn't know the constructions with `__call` and `__callStatic`. However, I still believe that a warning would make more good than harm. For example, in my examples I'm calling a field/method from the class itself (I'm using `$this`; `self` for static members). This is a class that I myself am declaring, so I (and the IDE) know for sure that such field/method doesn't exist. Why would I want to call an undefined member, on purpose, from the inside of the class? Even if the class were inheriting from another one, the IDE would know the type of the parent class (present in the `extends`) and could also know if the member exists or not.

In addition to all this, and in contrast to the 5 series, PHP added type declarations (a game-changer for static analysis) and even [it deprecated dynamic property declarations](https://php.watch/versions/8.2/dynamic-properties-deprecated) (present in your example), except for cases where we explicitly need dynamic objects. So, with the current state of PHP (and adding Composer to the mix), Isn't it more probable that a reference to an undefined member is a mistake and not made on purpose?


GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13458329

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "negora (via GitHub)" <gi...@apache.org>.
GitHub user negora added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

@matthiasblaesing Hi Matthias. Thank you for your response.

I've not programmed in PHP since the days of version 5.2, I believe. Back then, there was no way to declare the dependencies of our projects (or at least I didn't know any), so the policy that you talk about made much sense. But I wonder if, now that we've tools like Composer, it wouldn't make more sense that a reference to an undefined function cause at least a warning, so that the user is aware that either he has mistyped the name or that he has not added the proper dependency to `composer.json`.

I know that using Composer is not mandatory for a PHP project (I myself am still trying to incorporate it to my project), but if the mentioned warning could be toggled on/off (like others in Netbeans), we could choose according to the nature of each project.

Apart from this case, there are other 2 cases about which I've doubts:

* References to undefined fields.
* References to undefined methods.

For example, if I write this within a method of my class:

```php
self::foo();   // Nonexistent static method.
$this->foo;    // Nonexistent field.
$this->foo();  // Nonexistent method.
```

Shouldn't the editor emit 3 warnings?

I apologize in advance if I'm misunderstanding all this.

Thank you.


GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13429561

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
GitHub user matthiasblaesing added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

Are you looking for this?

```php
<?php

class Test {
    public function __call($name, $arguments) {
        if($name == 'hello') {
            printf("Hello %s\n", $arguments[0]);
        }
    }

    public static function __callStatic($name, $arguments) {
        if($name == 'flexibility') {
            printf("Isn't flexibility %s\n", $arguments[0]);
        }
    }
}

$t = new Test();
$t->foo();

$t->x = "Demo";

echo $t->x . "\n";

$t->hello("World");

Test::flexibility('ugly');
```

Sure, for selected cases you can do a full analysis, for others (like these) this won't work.

GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13434927

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
GitHub user matthiasblaesing added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

This could be implemented as an optional feature. but that needs someone to do it. Before any work is done I strongly suggest to coordinate with @junichi11 and @tmysik to see if such work will have the chance to be merged.

GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13474229

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "tmysik (via GitHub)" <gi...@apache.org>.
GitHub user tmysik added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

Thanks for your question.

PHP is a dynamic language, so it is always difficult to detect these situations (PHP is more like JavaScript than Java, in this particular case). The best you can do here is - to create an issue and assign it to @junichi11. We can evaluate, but please, keep in mind that it can easily happen that such a detection could have a big negative impact on the performance of the IDE (just an example situation that can happen). So, once such an issue is created, we can discuss it there. Please be sure that if it can be implemented in some reasonable way, there is a good chance that it will be done (BTW, patches are more than welcome, of coure :grin:).


GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13487205

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [D] PHP: Shouldn't a call to an undefined function trigger an error in the editor? [netbeans]

Posted by "negora (via GitHub)" <gi...@apache.org>.
GitHub user negora added a comment to the discussion: PHP: Shouldn't a call to an undefined function trigger an error in the editor?

Thank you all for your answers. They're very clarifying.

I must admit that discovering type declarations in PHP has changed my mind with regard to this potential hint (and others). I agree that, without types in the function parameters and returns, this hint would be useless once you crossed the boundary of a function. But explicit types allow a much more stricter analysis.

There would still be corner cases, of course. For example, if you don't use namespaces and declare 2 classes with the same name in your code base (in 2 different files). Wherever you instantiate any of these classes and call one of its methods, the analyzer will have to decide between:

* Either consider any method of that instance as existing (too lax).
* Or consider any method of that instance as non-existing (too strict).
* Or generate something like an intersection type in memory and consider methods of both classes as existing.

If I'm not mistaken, the PHP plugin of IntelliJ and the Intelephense plugin of Visual Studio Code have chosen the 3rd route.

I wish I had a deep knowledge about language analysis and, specially, the Netbeans internals (to help with this). But my knowledge is limited to Java back-end apps only :-/ .


GitHub link: https://github.com/apache/netbeans/discussions/8573#discussioncomment-13496484

----
This is an automatically sent email for notifications@netbeans.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@netbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists