Skip to content

Commit

Permalink
[php8.2-fix]: Fixed compatibility with PHP 8.2+
Browse files Browse the repository at this point in the history
It looks like 8.2 does not accept "tentative" void type
  • Loading branch information
mikhainin committed Nov 13, 2023
1 parent bc72c29 commit 51d1097
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Imagick.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ public function key(): int {}
//# endif
#endif

#if PHP_VERSION_ID < 80200
/** @alias Imagick::nextImage
* @tentative-return-type
*/
Expand All @@ -1280,7 +1281,10 @@ public function next(): void {}
* @tentative-return-type
*/
public function rewind(): void {}

#else
public function rewind(): void {}
public function next(): void {}
#endif
public function valid(): bool {}

public function current(): Imagick {}
Expand Down
8 changes: 7 additions & 1 deletion ImagickPixelIterator_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ ZEND_END_ARG_INFO()

#define arginfo_class_ImagickPixelIterator_key arginfo_class_ImagickPixelIterator_getIteratorRow

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ImagickPixelIterator_next, 0, 0, IS_VOID, 0)

#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ImagickPixelIterator_next, 0, 0, IS_VOID, 0)
#else
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ImagickPixelIterator_next, 0, 0, 0)
#endif

ZEND_END_ARG_INFO()

#define arginfo_class_ImagickPixelIterator_rewind arginfo_class_ImagickPixelIterator_next
Expand Down
49 changes: 48 additions & 1 deletion Imagick_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5097,10 +5097,35 @@ ZEND_END_ARG_INFO()
#define arginfo_class_Imagick_key arginfo_class_Imagick_getSizeOffset
#endif

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Imagick_next, 0, 0, IS_VOID, 0)
#if PHP_VERSION_ID < 80200

#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Imagick_next, 0, 0, IS_VOID, 0)
#else
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Imagick_next, 0, 0, 0)
#endif

ZEND_END_ARG_INFO()
#endif

#if PHP_VERSION_ID < 80200
#define arginfo_class_Imagick_rewind arginfo_class_Imagick_next
#endif

#if !(PHP_VERSION_ID < 80200)

#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Imagick_rewind, 0, 0, IS_VOID, 0)
#else
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Imagick_rewind, 0, 0, 0)
#endif

ZEND_END_ARG_INFO()
#endif

#if !(PHP_VERSION_ID < 80200)
#define arginfo_class_Imagick_next arginfo_class_Imagick_rewind
#endif

#define arginfo_class_Imagick_valid arginfo_class_Imagick_removeImage

Expand Down Expand Up @@ -6725,6 +6750,18 @@ ZEND_METHOD(Imagick, setResolution);
ZEND_METHOD(Imagick, setSamplingFactors);
ZEND_METHOD(Imagick, setSize);
ZEND_METHOD(Imagick, setType);
#if PHP_VERSION_ID < 80200
ZEND_METHOD(Imagick, nextImage);
#endif
#if PHP_VERSION_ID < 80200
ZEND_METHOD(Imagick, setFirstIterator);
#endif
#if !(PHP_VERSION_ID < 80200)
ZEND_METHOD(Imagick, rewind);
#endif
#if !(PHP_VERSION_ID < 80200)
ZEND_METHOD(Imagick, next);
#endif
ZEND_METHOD(Imagick, valid);
ZEND_METHOD(Imagick, current);
#if MagickLibVersion >= 0x659
Expand Down Expand Up @@ -7524,8 +7561,18 @@ static const zend_function_entry class_Imagick_methods[] = {
#if MagickLibVersion > 0x628
ZEND_MALIAS(Imagick, key, getIteratorIndex, arginfo_class_Imagick_key, ZEND_ACC_PUBLIC)
#endif
#if PHP_VERSION_ID < 80200
ZEND_MALIAS(Imagick, next, nextImage, arginfo_class_Imagick_next, ZEND_ACC_PUBLIC)
#endif
#if PHP_VERSION_ID < 80200
ZEND_MALIAS(Imagick, rewind, setFirstIterator, arginfo_class_Imagick_rewind, ZEND_ACC_PUBLIC)
#endif
#if !(PHP_VERSION_ID < 80200)
ZEND_ME(Imagick, rewind, arginfo_class_Imagick_rewind, ZEND_ACC_PUBLIC)
#endif
#if !(PHP_VERSION_ID < 80200)
ZEND_ME(Imagick, next, arginfo_class_Imagick_next, ZEND_ACC_PUBLIC)
#endif
ZEND_ME(Imagick, valid, arginfo_class_Imagick_valid, ZEND_ACC_PUBLIC)
ZEND_ME(Imagick, current, arginfo_class_Imagick_current, ZEND_ACC_PUBLIC)
#if MagickLibVersion >= 0x659
Expand Down
32 changes: 32 additions & 0 deletions imagick_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -8352,6 +8352,22 @@ PHP_METHOD(Imagick, setFirstIterator)
}
/* }}} */

/* {{{ proto bool Imagick::rewind()
Alias for "setFirstIterator" but retuns void
*/
PHP_METHOD(Imagick, rewind)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

zval retval;
ZVAL_UNDEF(&retval);
zend_call_method_with_0_params(Z_OBJ_P(getThis()), Z_OBJCE_P(getThis()), NULL, "setFirstIterator", &retval);
}
/* }}} */


/* {{{ proto bool Imagick::setLastIterator()
Sets the wand iterator to the last image.
*/
Expand Down Expand Up @@ -8423,6 +8439,22 @@ PHP_METHOD(Imagick, nextImage)
}
/* }}} */


/* {{{ proto bool Imagick::next()
Alias for "nextImage" but retuns void
*/
PHP_METHOD(Imagick, next)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

zval retval;
ZVAL_UNDEF(&retval);
zend_call_method_with_0_params(Z_OBJ_P(getThis()), Z_OBJCE_P(getThis()), NULL, "nextImage", &retval);
}
/* }}} */

/* {{{ proto bool Imagick::hasPreviousImage()
Returns true if the wand has more images when traversing the list in the reverse direction
*/
Expand Down

0 comments on commit 51d1097

Please sign in to comment.