vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

In php 5.6 the compatibility checking for ArrayAccess seems to be broken

Open Vilx2 opened this issue 2 years ago • 4 comments

Describe the bug Intellephsense complains that 3 of the 4 ArrayAccess methods have incompatible implementations when in fact they are completely correct:

  • Method 'Dummy::offsetExists()' is not compatible with method 'ArrayAccess::offsetExists()'.
  • Method 'Dummy::offsetSet()' is not compatible with method 'ArrayAccess::offsetSet()'.
  • Method 'Dummy::offsetUnset()' is not compatible with method 'ArrayAccess::offsetUnset()'.

To Reproduce

class Dummy implements ArrayAccess 
{
	public function offsetExists($offset) { return true; }
	public function offsetGet($offset) { return 42; }
	public function offsetSet($offset, $value) { }
	public function offsetUnset($offset) { }
}

Expected behavior No errors.

Platform and version

  • VS Code, latest version
  • Intellephsense, latest free version (1.8.2)
  • PHP version set to PHP 5.6.8

VS Code details:

Version: 1.65.2 (user setup)
Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
Date: 2022-03-10T14:33:55.248Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19044

Vilx2 avatar Mar 11 '22 23:03 Vilx2

Same bug, but with PHP 8.1.5

BraZucco avatar Jul 27 '22 03:07 BraZucco

Works for me when changed to:

class Dummy implements ArrayAccess 
{
	public function offsetExists($offset): bool { return true; }
	public function offsetGet($offset): mixed { return 42; }
	public function offsetSet($offset, $value): void { }
	public function offsetUnset($offset): void { }
}

RoswellCityUK avatar Aug 18 '22 10:08 RoswellCityUK

With type annotations it works, yes, but those are unavailable in PHP 5.6.

Vilx2 avatar Aug 18 '22 11:08 Vilx2

I'm having the same problem.

PHP 5.6 - function retrun type annotations are not available, so there is no way to clear this problem from the list.

shane-smith avatar Sep 06 '22 07:09 shane-smith

In intelephense 1.9 the error will be removed when targeting php version < 8.1. It remains for 8.1+ as php will throw deprecation notices https://wiki.php.net/rfc/internal_method_return_types .

bmewburn avatar Dec 28 '22 20:12 bmewburn

This error is still happening for me -- unless I add the return types as suggested by RoswellCityUK.

Intelephense 1.9.5

PHP Version 7.4.27

VS Code: Version: 1.75.1 (user setup) Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf Date: 2023-02-08T21:32:34.589Z Electron: 19.1.9 Chromium: 102.0.5005.194 Node.js: 16.14.2 V8: 10.2.154.23-electron.0 OS: Windows_NT x64 10.0.19045 Sandboxed: No

cdillon avatar Feb 26 '23 11:02 cdillon

I got this error whilre running my web app ( using laravel with php7.3 ) using homestead. It took me so long to finally found out that the error I got was from running php8 in the host machine.

So I change the php version from the host machine to 7.3 as well.

Now the problem has all gone.

I dont know why but apparently, the php in the host machine does affect the php in the homesteead as well.

So you need to make sure the php version in homestead is the same as the host machine.

idhamhafidz avatar Dec 22 '23 13:12 idhamhafidz