Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.4.0 - Register Globals Deprecated

Tags:

php

I ran across the page on PHP website saying globals will be depreciated in 5.4.0. I understand that $MyFormPost is a global vartiable of $_POST['MyFormPost'] and $_GET['MyFormPost'] but I am wondering if the way our website was developed if it would also be considered depreciated in 5.4.0.

We have a class which the contents have been posted below, that we can access all the common classes through our application. So if we want to access the users Browser Information to see the mobile device they are using in any of the other classes or files, we just call $gb->BrowserData->get_MobileDevice(). Do we need to start switching the way our site was built?

$gb = new GlobalData;

global $BrowserData;
$BrowserData = new BrowserType();

if ($gb->BrowserData->get_MobileDevice()=='iPhone') {

}

GlobalData.class.php

<?php
class GlobalData {
        public function __get($name) {
            if (isset($GLOBALS[$name]))
                return $GLOBALS[$name];
        }
}
?>
like image 880
Brad Wickwire Avatar asked Mar 07 '26 11:03

Brad Wickwire


1 Answers

That's not what register_globals is; you don't have to worry. It's been off by default since PHP 4.2, and it's about time it was removed. Here's a description of what register_globals actually does - basically throws all of the request variables into global variables. A very bad idea.

Although I would still recommend the use of global $somevariable; to bring global variables into the current scope, instead of having the kind of class you're using.

like image 144
Ry- Avatar answered Mar 10 '26 00:03

Ry-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!