I see your concern, but are you just using the error throwing as
almost a 'debug' mode feature? Or are you going to start doing try
and catches each time you do a getParameter? I think if you are using
it as a debug mode only you'd most likely catch the error while you
are testing the application. If you are just looking to do try and
catches, I'd suggest just using the hasParameter followed by the
getParameter, although I suppose you could make the type inbetween the
two.
One solution is you could override the getParameter yourself and just
add a check using has parameter, if it doesn't throw an sfError. This
might be the best solution. You could also make the check/error throw
if it is running dev mode only.
Daum
On Nov 27, 12:12 pm, Michal G <[EMAIL PROTECTED]> wrote:
> On Nov 27, 6:00 am, Daum <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > I don't know if getAttributeSafe would be any different from
> > getAttribute.
>
> > The question with getAttributeSafe and parameterSafe is how do you set
> > default values? For example you can do $request->getParameter
> > ('foobar','hello') it says if the parameter isn't set(is null) then
> > default to 'hello'. With getAttributeSafe what would it return if the
> > attribute is not safe? false? What if your parameter was false?
> > Null? Same problem as above, if you set the paramter to null. Do you
> > understand the problem here?
>
> > I think the best solution for this is the hasAttribute followed by a
> > getAttribute if it is true and you are worried about null
> > properties.
> > Daum
>
> First off all - when i mean that parameter is not set i mean it's not
> set. I don't mean it's set to null.
>
> Well, the main difference would be that i can't set default values,
> because
> when i use this function i *know* that parameter or attribute must be
> set. If not,
> it means that something wrong happened in my code. So it throws
> exception -
> it's not returning anything.
>
> I'm talking about situation like this:
>
> function executeAction($request) {
> // parameter value_to_add is required so i don't need default
> value
> $this->forward404unless($request->hasParameter("value_to_add"));
>
> [...]
>
> // i made stupid mistake in parameter name, so without any notice
> result could be wrong (null is converted to zero)
> $this->result = $someCalulatedValue + $request->getParameter
> ("valu_to_add"));
>
> // now attribute name is good, but someone has broken login
> function which should set this attribute - now it doesn't
> $this->somethingElse = $this->getUser()->getAttribute("some_var");
>
> }
>
> I think that it would be nice if i would have exception in those two
> situation. In those situation such safe function could be handy.
>
> Ideal solution for me would be to change getParameter behavior to
> something like that:
> "par" is not set:
>
> $request->getParameter("par"); // throws exception
> instead returning null, because i don't want default
> $request->getParameter("par", null); // now i want null as
> default, so return null
> $request->getParameter("par", "default"); // return "default"
>
> "par" is set to null:
> $request->getParameter("par"); // return par value,
> which is null
> $request->getParameter("par", null); // return default, which
> is null, so return null anyway
> $request->getParameter("par", "default"); // return "default"
>
> Only difference from current behavior is in first example.
>
> I know it's impossible to implement it (because of compatibility). I'm
> just thinking how it could
> be written to be safer to programmer mistakes.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---