Ah, that is true I have some work to do before I get the most basic elements of php ;) Thank you for the explanation and the validation, Peter !
2010/1/29 Peter Bowers <[email protected]>: > On Fri, Jan 29, 2010 at 7:51 AM, ABClf <[email protected]> wrote: >> if ($group != 'Private' && $action == 'edit') { >> include_once("$FarmD/cookbook/authorcontrib.php"); } > > This (above) is correct. > >> if (!$group == 'P' && $action == 'edit') { >> include_once("$FarmD/cookbook/authorcontrib.php"); } >> >> That blocks too other group. >> I don't see where is the trouble : doesn't the « if condition » says : >> if not group P + if action=edit ? > > You have a problem with the order of processing of operators. You are > assuming NOT (group == P) while it is actually being processed as > ((NOT GROUP) == P). > > Since all data types in PHP can be used as booleans (0 or blank or > null or whatever is false, other values are true) what you have done > is converted $group from a string to a boolean -- since $group always > has a value (i.e., boolean TRUE) then putting the ! in front of it > says "NOT $group" or boolean FALSE when $group contains something. > Thus when you are saying (!$group == 'P') it becomes (FALSE == 'P'). > > Anyway, that was a long explanation and maybe not so helpful. Here's > what you're looking for to implement the semantics you were aiming > towards: > >> if (!($group == 'P' && $action == 'edit')) { >> include_once("$FarmD/cookbook/authorcontrib.php"); } > > (Note the parentheses surrounding the entire inner conditional) > > This is kind of different than the way it's usually written, although > I may be just expressing my own stylistic preferences. I would tend > to write the same thing like this: > >> if ($group != 'P' || $action != 'edit') { >> include_once("$FarmD/cookbook/authorcontrib.php"); } > > Note the change of both == operators to != and the change of && to ||. > > -Peter > -- --------------------------------------- | A | de la langue française | B | http://www.languefrancaise.net/ | C | [email protected] --------------------------------------- _______________________________________________ pmwiki-users mailing list [email protected] http://www.pmichaud.com/mailman/listinfo/pmwiki-users
