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

Trying to access array offset on value of type null #14191

Open
gidzr opened this issue May 10, 2024 · 3 comments
Open

Trying to access array offset on value of type null #14191

gidzr opened this issue May 10, 2024 · 3 comments

Comments

@gidzr
Copy link

gidzr commented May 10, 2024

Description

The following code:

set_error_handler(function($errno, $errstr, $errfile, $errline ) {
      // Handle the error (e.g., display it in the browser)
      echo ":: CommonHelper Error Logger (set_error_handler section) ::--> [$errno] $errstr on line $errline in file $errfile <br><br>";
   }

in a class that is called on ajax post

public function(){
   
     print_r($_POST) 

}

Resulted in two inconsistent things occurring:

  1. the correct posted variables were printed.. but
  2. the commonhelper set_error_handler() function assessed the code before the $_POST variables were set, resulting in a NULL result from the error handlers view

This had flow-on effects whereby if I had strtoupper($_POST['varname']), it would both provide a correct result while simultaneously throwing a deprecation warning for strtoupper on a null value.

I can't find anything online to explain this.

PHP Version

8.1.17

Operating System

XAMPP

@nielsdos
Copy link
Member

Please provide a small code snippet that reproduces the problem, based on what you wrote here I can't reproduce the issue.

@gidzr
Copy link
Author

gidzr commented May 15, 2024

Yep - this is a weird one. The problem is that it might be an interaction between AJAX and PHP.. I'll try and provide a setup to minimally reproduce it, but I've never experienced this issue before despite repeating the exact approach numerous times.

I think this is because it's always been happening in the background, but as these are still only deprecation warnings, didn't bubble up to inspect/browser unless they occurred at the same time as another proper error.

The other issue is that the warning issued wasn't visible unless I double clicked on the resource under "Network" in the chrome inspect window. Which caused a new browser tab to open, showing the error.

The key takeout that I can see however, is that it appears there's a brief moment when the ajax calls a script, calling the script causes PHP to run/assess a function before the global POST variable is set, this results in a php deprecation warning that strtolower(can use null values), then the function runs with the POSTED value .. super weird.

Let me get some time to reproduce.

@nielsdos
Copy link
Member

I think that if you open a new window from the network tab, that Chrome resends the network request but without the POST variables. So that would explain at least the strange inconsistency there.

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

No branches or pull requests

2 participants