Fueling Your Coding Mojo

Buckle up, fellow PHP enthusiast! We're loading up the rocket fuel for your coding adventures...

Popular Searches:

In PHP 7.0, predefined variables such as "$REQUEST_METHOD" cannot be accessed

User: techlover91

Hey there,
I recently upgraded to PHP 7.0 and I'm facing an issue with accessing predefined variables like "$REQUEST_METHOD". I used to use this variable to determine the HTTP request method (GET, POST, etc.), but it seems like it's no longer working. Has anyone else encountered this problem after upgrading to PHP 7.0? Is there a new way to access the request method? Any help would be greatly appreciated.

All Replies


User 1: phpexpert21

Yes, I faced the same issue when I upgraded to PHP 7.0. In PHP 7.0, the way predefined variables like "$REQUEST_METHOD" are accessed has changed. Instead of directly accessing them, you can use the superglobal variable "$_SERVER['REQUEST_METHOD']" to get the request method.

For example, previously you might have written:
$method = $REQUEST_METHOD;

Now, you should update it to:

This change was introduced as part of PHP 7.0's effort to improve security and make the language more consistent. It's always a good practice to check the PHP documentation for any changes that might affect your code when upgrading to a new version.

I hope this helps! Let me know if you have any further questions or if there's anything else I can assist you with.


User 3: webmaster232

Hello techlover91,

I faced the exact same issue with predefined variables after upgrading to PHP 7.0. The reason behind this change is that PHP 7.0 introduced a more secure approach by disallowing direct access to predefined variables.

To access the request method in PHP 7.0, you need to rely on the $_SERVER superglobal array. The $_SERVER array contains various server and execution environment information, including the request method.

Instead of using "$REQUEST_METHOD", you should now use:

This will give you the request method, such as GET, POST, or PUT.

Remember, it's essential to keep your code up to date with the latest PHP versions to benefit from security enhancements and performance improvements.

If you have any more questions or face any other issues, feel free to ask. Happy coding!


User 2: codingnewbie23

Hey techlover91,

I also encountered the same issue after upgrading to PHP 7.0. It took me a while to figure out the solution, but I found that you can access the request method using the $_SERVER['REQUEST_METHOD'] superglobal.

Previously, I used to directly access "$REQUEST_METHOD" to get the request method. However, since PHP 7.0, this approach no longer works. Instead, you need to make use of the $_SERVER superglobal array, specifically the 'REQUEST_METHOD' index.

Here's an example of how you can retrieve the request method using the updated approach:

By making this change, you should be able to access the request method without any issues in your PHP 7.0 code.

If you have any further questions or need additional assistance, feel free to ask. Happy coding!

New to LearnPHP.org Community?

Join the community