We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Removing PHP4 reference assignments

Developer Preview

Adrian Macneil's avatar
Adrian Macneil
21 posts
about 12 years ago
Adrian Macneil's avatar Adrian Macneil

Hi team

I’m trying to do some neat things with unit testing in EE, and one of the biggest things getting in my way (believe it or not) is the PHP4-style variable reference assignments (=&) in system/codeigniter/system/core/CodeIgniter.php.

The reason for this is that if I require that file from within a function, the variables no longer have global scope. I would normally be able to work around this by declaring the globals manually (global $CFG etc), however PHP does not allow global variables defined inside a function to be assigned to by reference (source).

Ideally, you could replace all of these $CFG variables with the $GLOBALS[‘CFG’] syntax, so it is clear that they are always defined globally. However, if that is not possible, would you be able to simply remove the =& variable assignments (which have no effect in PHP5 anyway)?

Example:

$EXT =& load_class('Hooks', 'core');

Desired:

$EXT = load_class('Hooks', 'core');

Thanks!

       
Wes Baker's avatar
Wes Baker
343 posts
about 12 years ago
Wes Baker's avatar Wes Baker

I’m interested to hear more about where you’re going and we’d be happy to make this change, but we won’t be making it for 2.8. It’ll most likely be in the next release after that.

       
Adrian Macneil's avatar
Adrian Macneil
21 posts
about 12 years ago
Adrian Macneil's avatar Adrian Macneil

Ok. Well as long as it’s going to be the release after that, it would be awesome if you could separate the EE initialization code (loading classes, db configuration) from the actual page rendering. And also remove as much global state (global variables, constants etc) as possible.

I’m really just hacking around the EE loading code so that I can run PHPUnit tests and have EE methods work correctly. To do this, I need to initialize EE without actually rendering anything. Previously I simply mocked out the entire EE global object in my tests, however it’s a much better test of the whole system if some EE classes are available (especially when API changes are introduced in new versions of EE).

       
Wes Baker's avatar
Wes Baker
343 posts
about 12 years ago
Wes Baker's avatar Wes Baker
Ok. Well as long as it’s going to be the release after that, it would be *awesome* if you could separate the EE initialization code (loading classes, db configuration) from the actual page rendering. And also remove as much global state (global variables, constants etc) as possible.

We’d certainly like to head that direction, but it’ll be far longer before that. We should be able to replace the reference assignments for the next maintenance release though.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.