comanage-dev - Re: [comanage-dev] Code Diff
Subject: COmanage Developers List
List archive
- From: Benn Oshrin <>
- To:
- Subject: Re: [comanage-dev] Code Diff
- Date: Sat, 21 Feb 2015 10:29:44 -0500
Looks like I didn't have the latest version of the file, and Scott already changed it to
if(array_key_exists('cou_id', $this->data[$this->alias])) {
$couid = $this->data[$this->alias]['cou_id'];
} else {
return;
}
While this works here, I don't think it's as reliable as my version since if for some reason $this->alias is empty, you'll still throw a warning. You only need array_key_exists if you're trying to detect an actual 'null' value, otherwise isset() and empty() are more efficient.
Thanks,
-Benn-
On 2/20/15 9:49 PM, Benn Oshrin wrote:
As mentioned on today's dev call, here's an example from
CoPersonRole::afterSave()
// Since the Provisioner Behavior will only provision group
memberships
// for CO People with an Active status we do not need to manage
// membership in the members group based on status here. So we only
// add a CO Person to the COU members group whenever we detect
// the CO Person Record has a COU.
- $couid = $this->data[$this->alias]['cou_id'];
- if (empty($couid)) {
- return;
+ if(empty($this->data[$this->alias]['cou_id'])) {
+ return;
}
+ $couid = $this->data[$this->alias]['cou_id'];
PHP will evaluate $this->data[$this->alias]['cou_id'] before assigning
it to $couid, and if any component is invalid (data is empty, there is
no cou_id element, etc) will output a warning. So you can't assign and
then test for empty, you have to check for empty before you assign.
That's what the above diff does (as well as fixing some spacing issues).
(empty() and isset() will suppress warnings during evaluation.)
Thanks,
-Benn-
- [comanage-dev] Code Diff, Benn Oshrin, 02/21/2015
- Re: [comanage-dev] Code Diff, Benn Oshrin, 02/21/2015
Archive powered by MHonArc 2.6.16.