[pLog-svn] Rewrite of getSessionValue()
Ammar Ibrahim
ammar.ibrahim at gmail.com
Sat Jul 8 13:15:25 GMT 2006
The problem with the implementation that you provided is that there is two
exit points to the function which is not recommended. It could be a one
liner as follows:
return (isset($session[$keyName]) && $session[$keyName] != '' ) ?
$session[$keyName] : $defaultValue );
But I wouldn't recommned this as well for two reasons:
1- Performance
2- Readability
- Ammar
On 7/8/06, Jon Daley <plogworld at jon.limedaley.com> wrote:
>
> It looks alright, though I don't think it changes anything. A
> even simpler version is below. We don't have a place to check stuff in
> for fixes to 1.0.6, do we? This particular fix should not be the one to
> open a new branch, though if we do end up using one, this might as well
> get checked in. I can put this in 1.1, definitely.
>
> > function getSessionValue( $param, $defaultValue = "" )
> > {
> > $session = HttpVars::getSession();
> > $viewName = $this->className();
> > $keyName = "{$viewName}_{$param}";
> >
> > if ( isset($session[$keyName]) && $session[$keyName] != '' ){
> > return $session[$keyName];
> > } else {
> > return $defaultValue;
> > }
> > }
>
>
>
> On Sat, 8 Jul 2006, Ammar Ibrahim wrote:
>
> > While reading some code, I stumbled across getSessionValue() in
> > class/view/view.class.php . And I think the logic implemented is quite
> > complicated to do a really simple thing and there were a few mistakes
> like
> > putting a string variable between quotes. Here's a rewrite, could
> someone
> > please update the 1.0.6 branch, because I don't have SVN accesss.
> >
> > /**
> > * retrieves a parameter from the session
> > *
> > * @param param
> > * @param defaultValue
> > * @return The value associated to the parameter or empty if not
> > * found
> > */
> >
> > function getSessionValue( $param, $defaultValue = "" )
> > {
> > $session = HttpVars::getSession();
> > $viewName = $this->className();
> > $keyName = "{$viewName}_{$param}";
> >
> > $value = '';
> > if ( isset($session[$keyName]) && $session[$keyName] != '' ){
> > $value = $session[$keyName];
> > } else {
> > $value = $defaultValue;
> > }
> >
> > return $value;
> > }
>
> --
> Jon Daley
> http://jon.limedaley.com/
>
> There is forgiveness through the cross.
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.lifetype.net/mailman/listinfo/plog-svn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http:// devel.lifetype.net/pipermail/plog-svn/attachments/20060708/f0712ac9/attachment.html
More information about the pLog-svn
mailing list