TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-15-2010, 09:36 PM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default What does this function do?

Could someone briefly explain this function?

PHP Code:
function l($var
{
    global 
$l;
    return 
$l[$var];

Thanks!
Dave is offline  
Reply With Quote
Old 03-15-2010, 10:46 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

php Code:
$l = array( 'one' => 'value for one', 'two' => 'value for two' );

// These both assign 'value for one' to $value
$value = $l['one'];
$value = l( 'one' );

It's just an overcomplicated method to return a value of $l based on its key. It's also a waste of resources, considering it has to first retrieve $l from the global namespace, and then just pipes back a value that you could have easily gotten on your own (as illustrated above). It doesn't perform any error checking to see if the value exists and return a default if it doesn't, which is the only reason I could see it being useful.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
Dave (03-16-2010)
Old 03-16-2010, 10:35 AM   #3 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Well that's one of the most pointless functions I have seen in a good long while. Not only have you got the extra and unnecessary function call overhead, your also using a global variable, which as we all know can be linked to global warming and 3rd world debt.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 03-16-2010, 01:17 PM   #4 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

I thought that had all been disproved, and Al Gore had switched to .NET.
Dave is offline  
Reply With Quote
Old 03-16-2010, 03:00 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Al Gore created .NET, but he uses Basic.

3rd world countries have debt? I thought we gave them the option to offer up their first born sons to the Masons and then we supported them with supplies of AK-47s to handle any dissidents?
delayedinsanity is offline  
Reply With Quote
Old 03-18-2010, 02:56 PM   #6 (permalink)
The Contributor
 
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
Dr John is on a distinguished road
Default

Al Gore helped with the funding for .NET, long before global variables came along to personally help programmers.
__________________
www.kidneydialysis.org.uk
Dr John is offline  
Reply With Quote
Old 03-20-2010, 11:10 PM   #7 (permalink)
The Visitor
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
cerealgirl is on a distinguished road
Default

And isn't thisfunction a shining example of why we should comment our code and select logical function names...

Quote:
Originally Posted by Dave View Post
Could someone briefly explain this function?

PHP Code:
function l($var
{
    global 
$l;
    return 
$l[$var];

Thanks!
Ummm, I'm pretty sure it's a variable variable - basically a way to have a dynamically named variable. Here they are in the manual http://php.net/manual/en/language.va...s.variable.php
Cool though they may be, I never use variable variables, because they're a bit confusing - they save a few lines of code but lose maintainability and readability IMHO.
cerealgirl is offline  
Reply With Quote
Old 03-21-2010, 05:24 AM   #8 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Quote:
Originally Posted by cerealgirl View Post
And isn't thisfunction a shining example of why we should comment our code and select logical function names...


Ummm, I'm pretty sure it's a variable variable - basically a way to have a dynamically named variable. Here they are in the manual http://php.net/manual/en/language.va...s.variable.php
Cool though they may be, I never use variable variables, because they're a bit confusing - they save a few lines of code but lose maintainability and readability IMHO.
Brackets not curly braces.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 03-21-2010, 05:40 AM   #9 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

php Code:
foreach ( $_POST as $key => value )
    $_POST[$key] = my_sanitize( $value, $args );

extract( $_POST );

// or

foreach ( $_POST as $key => $value )
    ${$key} = my_sanitize( $value, $args );

No readability lost there. :) Not exactly the best use case example in the world, but in the end variable variables are just helpful shortcuts for those who like them.
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM


All times are GMT. The time now is 11:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design