recaptcha
recaptcha copied to clipboard
Fix PHP 8.1 deprecations are being triggered in Response.php.
Fixes issue #490
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
For more information, open the CLA check for this pull request.
@googlebot Would have been nice to get this out with a new tag. This error creates problems.
Would be great to have this merged.
I want to upgrade the PHP version for some of my websites and this bug is a problem that prevents me from doing it! It seems there is a missing CLA that prevents the process of merging this PR. I think as it's an old PR the best way to fix this problem is to create a new PR almost identical to this one!
All contributors are covered under a CLA with Google, see https://github.com/google/recaptcha/pull/491/checks @rowan-m Could you help to merge this PR?
@anprok My apologies, I simply clicked on the link in the "google-cla" comment and forgot to hit the refresh button.
Thanks for the update - taking a look!
4 months have passed. This is a super easy fix. What is the problem with merging this?....
@rowan-m How about merging this, so people can resolve this error and not have to deal with forking this repo.
Please merge
@rowan-m please!
Google wonders why none of their products are a success. It's because they don't support anything. At this point... why invest in adopting or using a Google product when in short time, it's going to be abandoned. Relevant and timely article just the other day on this topic:
https://techcrunch.com/2022/10/01/stadia-died-because-no-one-trusts-google/
Another +1 for merge, please!
+1 please merge
7 months have passed. Please merge. @rowan-m @google-ospo-team @google-admin ?
@rowan-m need merge this!
I'm also waiting for the merge, but in the meantime I recommend using @ before the method :)
$recaptcha = new \ReCaptcha\ReCaptcha($recaptcha_secret_key);
$response = @$recaptcha->setExpectedHostname($hostname)->verify($recaptcha_response, $client_ip);
For anyone stumbling on this PR since Google doesn't seem to pay attention to this repository, if you're willing to use the cweagans/composer-patches
package in your app, adding this patch will address or silence the deprecations coming from changes in PHP 8.1 or 8.2.
diff --git a/src/ReCaptcha/ReCaptcha.php b/src/ReCaptcha/ReCaptcha.php
index 31ec44a..af8f465 100644
--- a/src/ReCaptcha/ReCaptcha.php
+++ b/src/ReCaptcha/ReCaptcha.php
@@ -37,6 +37,7 @@ namespace ReCaptcha;
/**
* reCAPTCHA client.
*/
+#[\AllowDynamicProperties]
class ReCaptcha
{
/**
diff --git a/src/ReCaptcha/Response.php b/src/ReCaptcha/Response.php
index 55838c0..e5ae53d 100644
--- a/src/ReCaptcha/Response.php
+++ b/src/ReCaptcha/Response.php
@@ -95,11 +95,11 @@ class Response
return new Response(false, array(ReCaptcha::E_INVALID_JSON));
}
- $hostname = isset($responseData['hostname']) ? $responseData['hostname'] : null;
- $challengeTs = isset($responseData['challenge_ts']) ? $responseData['challenge_ts'] : null;
- $apkPackageName = isset($responseData['apk_package_name']) ? $responseData['apk_package_name'] : null;
+ $hostname = $responseData['hostname'] ?? '';
+ $challengeTs = $responseData['challenge_ts'] ?? '';
+ $apkPackageName = $responseData['apk_package_name'] ?? '';
$score = isset($responseData['score']) ? floatval($responseData['score']) : null;
- $action = isset($responseData['action']) ? $responseData['action'] : null;
+ $action = $responseData['action'] ?? '';
if (isset($responseData['success']) && $responseData['success'] == true) {
return new Response(true, array(), $hostname, $challengeTs, $apkPackageName, $score, $action);
I guess one of the 2023 changes I'll be rolling out to our clients is removing this package as a dependency due to lack of maintenance.
For those not willing to use composer patches, I've created a fork with a branch that implements all changes needed for php 8.0, 8.1 and 8.2 compatibility here: https://github.com/8ctopus/recaptcha/commits/php8.2
To use it, you will need to update composer.json
as follows:
{
"require": {
"google/recaptcha": "dev-php8.2"
},
"repositories": [{
"type": "git",
"url": "https://github.com/8ctopus/recaptcha.git"
}]
}
It uses PR #460, #491 and #514.