TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   The Lounge (http://www.talkphp.com/lounge/)
-   -   When was the last time you used the global construct? (http://www.talkphp.com/lounge/2114-when-last-time-you-used-global-construct.html)

Wildhoney 01-27-2008 03:15 PM

When was the last time you used the global construct?
 
If you remember, the global construct allows you to bring in variables to use in a function that didn't declare them. Like so:

php Code:
$iX = 2;
$iY = 3;

function multiply()
{
    global $iX, $iY;
    return $iX * $iY;
}

echo 'Total: ' . multiply();

However, I really cannot remember the last time I used that in any of my scripts - thanks to OOP! How about everybody else?

Salathe 01-27-2008 04:20 PM

In my own everyday coding, the use of global has pretty much vanished. However, recently I've been playing with Wordpress which relies very heavily on some variables in the global scope so global is the usual practice there.

Alan @ CIT 01-27-2008 05:24 PM

It's been so long since I've used it that I can't rightly remember, but I'd say at least 2 years ago, probably longer.

Alan

Wildhoney 01-27-2008 05:25 PM

Would you say Wordpress is badly coded?

Alan @ CIT 01-27-2008 05:39 PM

Wordpress isn't "badly" coded as such, it's just like many large scripts (in particular vBulletin - seen the AdminCP code recently? :-D) in that it's littered with legacy code that was acceptable back then, but is less acceptable nowadays.

Alan

xenon 01-27-2008 06:02 PM

Quote:

Originally Posted by Wildhoney (Post 9781)
Would you say Wordpress is badly coded?

I'd say it's excessively procedural (even in some cases where an OO approach would have been more appropriate), making it very hard to extend.

Orc 01-28-2008 05:06 AM

I've used it once in my code, then I stopped considering, I felt that it wasn't needed. :/

ReSpawN 01-28-2008 05:47 PM

I might be the retarded farmer here but I still use globals in my email function. Since I am retrieving the system email and system administrator globally, I am going to set them for my function.

... What would be an alternative. I am here to learn so ... gimme some feedback on that one. I have no idea what the alternative could be. I assume you will want to retrieve some information and not do a query every time a for loop runs though the function.

RobertK 01-28-2008 06:33 PM

In my procedural projects, smaller things, I certainly do use it for handling the Database reference. However it is an object in most my work, and it frees itself. ;-)

I've not quite figured out the nuances of full on OOP/MVC design just yet.

xenon 01-28-2008 07:12 PM

And to be on topic, I don't use the construct for my own projects, but I do use it alot at work (where I work with code written even 5 years ago).

Village Idiot 01-28-2008 07:53 PM

Quote:

Originally Posted by Wildhoney (Post 9781)
Would you say Wordpress is badly coded?

By all means, yes.

On subject, I cant remember the last time I used it.

RobertK 01-28-2008 08:41 PM

Quote:

Originally Posted by Wildhoney (Post 9781)
Would you say Wordpress is badly coded?

In my own past uses I would say "kind of". Obviously it has an aging code base, and isn't been refactored into more efficient or relevant code. This lack of finesse for relatively simplistic things is a bad sign of what PHP can do, but ultimately not our responsibility. And yes, that's why I decided to make my own blog package for my own personal use, perhaps for others too, because I hate weighty packages for simplistic things. And secure software needn't be weighty, just secure!

So, badly coded ... sorta. But yet it does function and is popular.


All times are GMT. The time now is 06:22 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0