PHP Classes

The use of $GLOBALS makes me cringe

Recommend this page to a friend!

      HTML Parser  >  All threads  >  The use of $GLOBALS makes me cringe  >  (Un) Subscribe thread alerts  
Subject:The use of $GLOBALS makes me cringe
Summary:Dont use the global namespace!
Messages:2
Author:Simon
Date:2015-06-05 12:45:21
 

  1. The use of $GLOBALS makes me cringe   Reply   Report abuse  
Picture of Simon Simon - 2015-06-05 12:45:22
Take the following code

$htmlTree = array("Something", 123); // Some variable

include('html.parser.class.php');
$parser = new html_parser;

// $htmlTree is now an empty string!


On a somewhat related note, I highly recommend reading and following the guidelines here: http://www.phptherightway.com/

  2. Re: The use of $GLOBALS makes me cringe   Reply   Report abuse  
Picture of Dave Smith Dave Smith - 2015-06-05 13:03:08 - In reply to message 1 from Simon
Since $htmlTree is in the global namespace, I highly recommend that you do not use it for your array to avoid clashing. Use $localTree instead.

Keep in mind that there is your way, their way and my way. I am currently doing it my way :)

I will eventually move it over as a class property, in the meantime the license allows you to take this FREE code and modify it however it best fits your needs.

Dave