Welcome Guest, Not a member yet? Register   Sign In
VScode - undefined 'getVar' method in version 4.1.2
#1

(This post was last modified: 05-22-2021, 04:12 PM by wdeda.)

When version 4.1.1 was launched the extension "intelephense" in VScode, when using the methods 'getPost', 'getGet' or 'getVar' the alert message: "Undefined method getVar'.intelephense (1013)" was displayed. Several reports of the problem were made on Github and the solution given can then be seen at
https://github.com/bmewburn/vscode-intel...ssues/1670.
The solution given:
"If you look at the src for 4.0.1 $request is typed as HTTP\IncomingRequest which is the concrete class that declares a getVar function. Then in 4.1 it has become RequestInterface which does not declare getVar.

You may be able to override it by creating a non-executable ide helper file in your project root that types $ request as the concrete type." :

PHP Code:
namespace CodeIgniter;

/**
 * Class Controller
 */
class Controller
{
 
/**
 * Instance of the main Request object.
 *
 * @var HTTP\IncomingRequest
 */
 
protected $request;


"HTTP \ Incoming Request" changed again? Do you have any possible solution?

Update:
I went to check if there was a change and found that there was a change, as shown below:

PHP Code:
/**
 * Instance of the main Request object.
 *
 * @var HTTP\RequestInterface
 */
 
protected $request

I made the change to the request.php file but the problem was not solved, I will try a solution with the developers on Github.
Reply
#2

It’s a known issue and being worked on, but it is part of something much bigger so probably won’t have a short-term solution: https://github.com/codeigniter4/CodeIgni...ssues/4356. If you can share the actual files and context where you receive the error we may be able to add some more typehints like the one above you mentioned on BaseController.

One more thing, make sure your typehint is to the correct namespaced class. Using “HTTP\IncomingRequest” won’t work from the Controllers namespace - you need “CodeIgniter\HTTP\IncomingRequest”
Reply
#3

My apologies, I was doing testing the new version of the CI in PHP 8.0.6, XAMPP, and inattention in some configurations ended up generating the error.
Exceptional behavior in PHP 8, running without any problem, only during installation with Composer there was an alert for "extension gd2.dll not found" despite being in the extensions folder. I used php.ini from the previous version, 7.14. I disabled it.
Reply
#4

(This post was last modified: 05-26-2021, 10:27 PM by wdeda.)

When taking a screenshot of VScode showing the version of CodeIgniter, 4.1.2, and PHP, 8.0.6, running without problems, I found a series of error messages in Inteliphense 1.7.1, in the file 'codeigniter.php' , in the system folder, as shown in the image below.

Obviously, I presume, the occurrence of errors does not depend on the version of PHP used.

Attached Files Thumbnail(s)
   
Reply
#5

(05-26-2021, 10:25 PM)wdeda Wrote: When taking a screenshot of VScode showing the version of CodeIgniter, 4.1.2, and PHP, 8.0.6, running without problems, I found a series of error messages in Inteliphense 1.7.1, in the file 'codeigniter.php' , in the system folder, as shown in the image below.

Obviously, I presume, the occurrence of errors does not depend on the version of PHP used.

You may need reindex the workspace - press ctrl+shift+p (Windows), type intelephense and select Index workspace
Reply
#6

I thought about it and opened a single host in VScode and the problem persists.
Reply
#7

This is because of the incomplete interface dependence CI4 has. It is typehinted to the interfaces but those interfaces clearly do not have the methods being called as those methods are defined in the implementing classes. You can safely ignore those intelephense errors for now.

For the Kint error, the CodeIgniter class has a custom autoloader for Kint, which class alias `Kint\Kint` as only `Kint`. Since intelephense indexes based on the vendor/autoload.php, it doesn't understand the `Kint` alias. Ignore for now, please.
Reply
#8

(05-27-2021, 09:20 AM)paulbalandan Wrote: This is because of the incomplete interface dependence CI4 has. It is typehinted to the interfaces but those interfaces clearly do not have the methods being called as those methods are defined in the implementing classes. You can safely ignore those intelephense errors for now.

For the Kint error, the CodeIgniter class has a custom autoloader for Kint, which class alias `Kint\Kint` as only `Kint`. Since intelephense indexes based on the vendor/autoload.php, it doesn't understand the `Kint` alias. Ignore for now, please.

Of course, these error messages from Intelephense do not interfere with anything in the use of the framework, it is just a matter of believing that everything that deserves to be done deserves to be done well.

It is also a response to the MGatner request, "If you can share the current files and context where you receive the error we may be able to add some more typehints like the one above you mentioned on BaseController.". By the way, since then I stopped using the typehint suggested by the Intelephense team.

As stated earlier, these error messages were found accidentally, I rarely access the 'system' folder, my knowledge is minimal and I believe it is something that concerns only the framework development team.

I thank you @paulbalandan for the attention and kindness, your post is already a typehint.
Reply
#9

(This post was last modified: 05-28-2021, 11:22 AM by mlurie.)

I found a solution on the PHP Intelephense GitHub page here: https://github.com/bmewburn/vscode-intel...ssues/1670.  Add the following code to your Base Controller:


PHP Code:
       /**
     * Instance of the main Request object added to prevent the
     * PHP Intelephense VS Code plug-in from falsely reporting
     * IncomingRequest class errors.
     *
     * @var HTTP\IncomingRequest
     */
    
protected $request
Reply




Theme © iAndrew 2016 - Forum software by © MyBB