Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Compatibility with PHP 8.2 #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pmurzakov
Copy link
Contributor

@pmurzakov pmurzakov commented Sep 9, 2022

Most of issues with PHP 8.2 are caused by dynamic properties deprecations

So in order to resolve the issues I explicitly declared 2 properties in Memcache class. In the future it is possible to add type hint to connection property but it would break BC. (there is even a test which check if connection is possible to set to true)

Also there were some minor incompatibilities in tests which were fixed.

I checked on PHP 8.2.0RC1.

Before the patch:

> =====================================================================
> TEST RESULT SUMMARY
> ---------------------------------------------------------------------
> Exts skipped    :    0
> Exts tested     :   27
> ---------------------------------------------------------------------
> 
> Number of tests :   87                 1
> Tests borked    :   79 ( 90.8%) --------
> Tests skipped   :    7 (  8.0%) --------
> Tests warned    :    0 (  0.0%) (  0.0%)
> Tests failed    :    0 (  0.0%) (  0.0%)
> Tests passed    :    1 (  1.1%) (100.0%)
> ---------------------------------------------------------------------
> Time taken      :    0 seconds
> =====================================================================

With this patch:

> =====================================================================
> TEST RESULT SUMMARY
> ---------------------------------------------------------------------
> Exts skipped    :    0
> Exts tested     :   26
> ---------------------------------------------------------------------
> 
> Number of tests :   87                76
> Tests skipped   :   11 ( 12.6%) --------
> Tests warned    :    0 (  0.0%) (  0.0%)
> Tests failed    :    0 (  0.0%) (  0.0%)
> Tests passed    :   76 ( 87.4%) (100.0%)
> ---------------------------------------------------------------------
> Time taken      :    5 seconds
> =====================================================================

@pmurzakov pmurzakov marked this pull request as ready for review September 9, 2022 13:50
@pmurzakov pmurzakov changed the title Prepare for PHP 8.2 Compatibility with PHP 8.2 Sep 9, 2022
@remicollet
Copy link
Contributor

It looks some others are missing (username / password)
See https://github.com/websupport-sk/pecl-memcache/blob/NON_BLOCKING_IO_php8/src/memcache.c#L2532

(the reason why I go to the trivial way in pr #104)

…mcache->setSaslAuthData() and memcache_set_sasl_auth_data()
@pmurzakov
Copy link
Contributor Author

@remicollet thank you so much for pointing to this.
Apparently it means that there are no tests for memcache_set_sasl_auth_data() as well as for MemcachePool::setSaslAuthData().

I've just added the tests as well as declared username and password fields explicitly.
Could you please review this?

@@ -1546,15 +1573,15 @@ static void php_mmc_set_failure_callback(mmc_pool_t *pool, zval *mmc_object, zva
callback_tmp = *callback;
zval_copy_ctor(&callback_tmp);

add_property_zval(mmc_object, "_failureCallback", &callback_tmp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_property_zval frees the old value of _failureCallback, but the old code might leak the old value (ZVAL_COPY overwrites without checking the original value). It should be safe to keep the original code (not a performance sensitive part)?

E.g. add tests of calling https://www.php.net/manual/en/memcache.setserverparams.php more than once with a non-null failure callback and run in a debug php build


zval_ptr_dtor(&callback_tmp);

pool->failure_callback_param = *mmc_object;
Z_ADDREF_P(mmc_object);
}
else {
add_property_null(mmc_object, "_failureCallback");
ZVAL_NULL(Z_MEMCACHE__FAILURECALLBACK_P(mmc_object));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -1333,7 +1360,7 @@ static void php_mmc_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool persistent)
list_res = zend_register_resource(pool, le_memcache_pool);
mmc_object = return_value;
object_init_ex(mmc_object, memcache_ce);
add_property_resource(mmc_object, "connection", list_res);
ZVAL_RES(Z_MEMCACHE_CONNECTION_P(mmc_object), list_res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code would free the original property value if something set it before the call to connect (e.g. user manually calling <?php $memcache->connection = new stdClass(); $memcache->connect();)

pool = mmc_pool_new();
pool->failure_callback = (mmc_failure_callback) &php_mmc_failure_callback;
list_res = zend_register_resource(pool, le_memcache_pool);
add_property_resource(mmc_object, "connection", list_res);
ZVAL_RES(Z_MEMCACHE_CONNECTION_P(mmc_object), list_res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

original code would free the old value of $memcache->connection, this replacement just overwrites without checking the old value. (e.g. $memcache->connection = new stdClass(); $memcache->addServer(...); would no longer free the stdClass)

It isn't performance sensitive for something that'd be called once total per Memcache instance

@TysonAndre
Copy link
Contributor

The rest of the PR looks correct at a glance

@andypost
Copy link
Contributor

Is this still required or #104 is enough?

@pmurzakov
Copy link
Contributor Author

#104 is enough to make the extension compatible with PHP 8.2.
But in my opinion this one is slightly better as it explicitly declares all the properties instead of allowing them to be declared implicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants