[TYPO3-dev] Getting id of the page

Heiner Lamprecht typo3 at heiner-lamprecht.net
Mon Aug 28 10:41:50 CEST 2006


On Monday 28 August 2006 10:11, Tapio Markula wrote:
>
> What's wrong with this method.
> Why I should for every instance of needing $_GET parameter use
> directly t3lib_div::_GET() instead referring to it once
> before each series of needed information from $_GET parameter
> $_GET=t3lib_div::_GET();
> 		if(isset($_GET['id'])) // BE: current page in several modules;
> FE: always 'Web > List' + 'Page Properties', 'New page' and 'New
> content element',  if pop-up windows has not been used
> 			$id = $_GET['id'];
> 		elseif(isset($_GET['edit']['pages'])) // FE: 'Page properties'
> if pop-up windows has been used
> 			$id = key($_GET['edit']['pages']);
> that is easier to read than
>
> 		if(isset(t3lib_div::_GET('id'))

I don't think, it's easier to read.  $_GET is referred to as a 
superglobal variable.  So if an other developer reads a line like

$id = $_GET['id'];

he will most likely assume, that $_GET is really what it's supposed 
to be according to PHP documentation.  If you want to save source 
code size and performance, IMHO it would be better to do something 
like

$myGet = t3lib_div::_GET();

...

$id = $myGet['id'];


Now, it's clear to everybody, that $myGet is different from the 
superglobal $_GET.

The performance will be the same, but it's more clear to everyone 
who reads the code.


    Heiner

-- 
    heiner at heiner-lamprecht dot net    GnuPG - Key: 9859E373
  Fingerprint:  3770 7947 F917 94EF 8717 BADB 0139 7554 9859 E373




More information about the TYPO3-dev mailing list