tel8618217223380 / prado3

Automatically exported from code.google.com/p/prado3
Other
0 stars 0 forks source link

Some THttpRequest methods raise NOTICE level errors on missing headers #383

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some THttpRequest methods seem to make Prado scripts unneccessarily raise 
NOTICE level error messages (ie. [Notice] Undefined index: XYZ) when certain 
HTTP headers aren't supplied (for whatever reason) in the request initating the 
page download.

For ex. THttpRequest::getUserHost() checks whether there's a REMOTE_HOST header 
supplied, and if it isn't, it gracefully returns an empty string instead. 
However, ::getUserHostAddress(), ::getUserAgent(), etc. all raise NOTICEs if 
their respective headers aren't present in the request. I see no logic behind 
this, as none of these are mandatory HTTP headers, and their presence is not 
critical for the Prado framework to function properly. 

Therefore I propose the modification of said methods so all of them will 
gracefully return empty strings - or whatever value appropriate - if their 
respective headers aren't present in the $_SERVER array. However, instead of 
the "return isset($_SERVER[$x]) ? $_SERVER[$x] : ''" form it would be simpler 
to use the error supression prefix @, like "return @$_SERVER[x]". The latter 
will return NULL if the header is not present (which in turn will convert to an 
empty string if interpreted as / juggled to such), and the supplied value if 
the header is present.

Original issue reported on code.google.com by google...@pcforum.hu on 28 Jan 2012 at 7:49

GoogleCodeExporter commented 9 years ago
Patched in r3099.
From some quick tests the use of the simpler "@-way" seems to be a 1.75x slower 
the the isset/ternary operator alternative. No real deal, but i preferred the 
faster one.
Some of the old methods (getQueryString and getHttpProtocolVersion) previously 
returned an empty string; all the methods have been paired up to return null 
instead.

Original comment by ctrlal...@gmail.com on 29 Jan 2012 at 11:48