Skip to content

Incorrect PHP reflection type for Memcached::cas $cas_token #523

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
gdejong opened this issue Nov 12, 2022 · 1 comment
Closed

Incorrect PHP reflection type for Memcached::cas $cas_token #523

gdejong opened this issue Nov 12, 2022 · 1 comment

Comments

@gdejong
Copy link

gdejong commented Nov 12, 2022

The first argument ($cas_token) to Memcached::cas is a float according to the documentation.

image

However when using Reflection to list the parameters it determines that the $cas_token is of type string.

PHP script:

<?php
declare(strict_types=1);

$class = Memcached::class;
$method_to_inspect = "cas";

$method = new ReflectionMethod($class, $method_to_inspect);

echo "PHP version: " . PHP_VERSION . PHP_EOL;
echo "memcached version: " . phpversion("memcached") . PHP_EOL;
echo "Reflecting $class::$method_to_inspect" . PHP_EOL;


foreach ($method->getParameters() as $parameter) {
    echo "-  " . $parameter->getDeclaringClass()->getName() . "::" . $parameter->getName() . PHP_EOL;
    echo "   " . "type: " . $parameter->getType()->getName() . PHP_EOL;
}

results in

PHP version: 8.1.12
memcached version: 3.2.0
Reflecting Memcached::cas
-  Memcached::cas_token
   type: string
-  Memcached::key
   type: string
-  Memcached::value
   type: mixed
-  Memcached::expiration
   type: int

Dockerfile:

FROM php:8.1-cli-alpine

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && install-php-extensions memcached

Where does this inconsistency come from and can it be resolved?

A possible explanation is https://github.com/php-memcached-dev/php-memcached/blob/master/php_memcached.stub.php#L34
This stub file type hints the $cas_token parameter as being a string.

public function cas(string $cas_token, string $key, mixed $value, int $expiration=0): bool {}
@remicollet
Copy link
Collaborator

According to the code, the $cas_token should be an unsigned 64-bit integer (library side). In the extension valid type are integer, float and string (converted to uint64_t), but all type are accepted (so mixed).

m6w6 added a commit that referenced this issue Sep 26, 2024
- Add #515 option to locally enforce payload size limit
- Add #539 zstd support
- Add #540 compression_level option
- Mark password as a sensitive param for PHP 8.2
- Fix Windows PHP 8 compatibility
- Fix #518 Windows msgpack support
- Fix #522 signed integer overflow
- Fix #523 incorrect PHP reflection type for Memcached::cas $cas_token
- Fix #546 don't check key automatically, unless client-side verify_key is enabled
- Fix #555 incompatible pointer types (32-bit)
m6w6 added a commit that referenced this issue Oct 4, 2024
    - Add #515 option to locally enforce payload size limit
    - Add #539 zstd support
    - Add #540 compression_level option
    - Mark password as a sensitive param for PHP 8.2
    - Fix Windows PHP 8 compatibility
    - Fix #518 Windows msgpack support
    - Fix #522 signed integer overflow
    - Fix #523 incorrect PHP reflection type for Memcached::cas $cas_token
    - Fix #546 don't check key automatically, unless client-side verify_key is enabled
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants