ndunand / moodle-enrol_attributes

This plugin allows users to be enrolled according to any value stored in their user profile.
https://moodle.org/plugins/enrol_attributes
18 stars 22 forks source link

Fix for Undefined argv and Deprecated strpos() Issues #59

Open Buda9 opened 2 months ago

Buda9 commented 2 months ago

This PR addresses warnings and deprecations related to accessing the argv key in $_SERVER and passing a null value to the strpos() function in PHP 8.1.

2024/09/10 13:00:40 [error] 2304450#2304450: *249549 FastCGI sent in stderr: "PHP message: PHP Warning: Undefined array key "argv" in /example.com/public_html/enrol/attributes/lib.php on line 252PHP message: PHP Warning: Trying to access array offset on value of type null in /example.com/public_html/enrol/attributes/lib.php on line 252PHP message: PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /example.com/public_html/enrol/attributes/lib.php on line 252" while reading upstream, client: 23.88.105.37, server: example.com, request: "GET /admin/cron.php?password=... HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.1-fpm-example.com.sock:", host: "example.com"

Issues:

  1. PHP Warning: Undefined array key "argv" — Occurs when trying to access a non-existent argv key in the $_SERVER superglobal.
  2. PHP Warning: Trying to access array offset on value of type null — Triggered when attempting to access an array index that is null.
  3. PHP Deprecated: strpos(): Passing null to parameter # 1 ($haystack) of type string is deprecated — Occurs when null is passed as the first argument to strpos(), which is deprecated in PHP 8.1.

Changes made:

  1. Added a check to ensure that $_SERVER['argv'] is set and not null before accessing it.
  2. Replaced the strpos() call with a safer approach, handling potential null values.