VSCode intelephense finds `CLIRequest` instead of `IncomingRequest`
PHP Version
8.2
CodeIgniter4 Version
4.4.1
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
In Visual Studio Code got intelephense(1006) error when I try to use getPost() as string, because it is found the method from CodeIgniter\HTTP\CLIRequest::getPost that return only array or null. Are you sure that is correct? If i give an index even in CLI, why I get array?
The CodeIgniter\HTTP\IncomingRequest::getPost give a correct return type list, but unfortunately the intelliphense found the CLI first.
Steps to Reproduce
$json = json_decode($this->request->getPost('json'), true);
"Expected type 'string'. Found 'array|null'.intelephense(1006)"
Expected Output
@return array|bool|float|int|object|string|null
Anything else?
No response
If i give an index even in CLI, why I get array?
If you give an index in CLI, you will get null.
There is no $_POST data in CLI.
I don't know why your IDE find CodeIgniter\HTTP\CLIRequest.
I don't know why your IDE find
CodeIgniter\HTTP\CLIRequest.
It is common problem with intelephense: if it found more than one method, using only the first. The order is maybe ABC order ... I do know how many ppl using VSC but this is problem for all of us. I need to rewrite the CI core after every update ...
Try to remove CLIRequest from:
https://github.com/codeigniter4/CodeIgniter4/blob/689c93377b7125b5358a6093b2efecd132d20e70/app/Controllers/BaseController.php#L27
I've seen it too. this is because of the BaseController. you can delete typehint if you don't run the controller in the console
Try to remove
CLIRequestfrom:https://github.com/codeigniter4/CodeIgniter4/blob/689c93377b7125b5358a6093b2efecd132d20e70/app/Controllers/BaseController.php#L27
Hey, You give me an idea and it is working. On the same line, change the order:
* @var IncomingRequest|CLIRequest
Or remove CLIRequest like you suggest. Thanks mate!