Skip to main content

Risoluzione comparazioni deboli

# Strings (you are sure that the variable is a string!)

Before:
```php
if ($a == '') {
	// ...
}
```

After:
```php
if (empty($a)) {
	// ...
}
```

Before:
```php
if ($a != '') {
	// ...
}
```

After:
```php
if (!empty($a)) {
	// ...
}
```

# Checkbox value

Before:
```php
if ($a == 0) {
	// ...
} elseif ($a == 1) {
	// ...
} else {
	// ...
}
```

After:
```php
if (strval($a) === '0') {
	// ...
} elseif (strval($a) === '1') {
	// ...
} else {
	// ...
}
```

# Picklist value

Before:
```php
if ($a != '') {
	// ...
}
```

After:
```php
if ($a !== '') {
	// ...
}
```

# Permissions (profileGlobalPermission, profileTabsPermission, profileActionsPermission, ...)

Before:
```php
if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || $module == 'Users') {
	// ...
}
```

After:
```php
if ($is_admin == true || $profileGlobalPermission[1] === 0 || $profileGlobalPermission[2] === 0 || $module == 'Users') {
	// ...
}
```

# PearDatabase

Before:
```php
if ($adb->num_rows($result) == 0) {
	// ...
}
```

After:
```php
if ($adb->num_rows($result) === 0) {
	// ...
}
```

Before:
```php
if ($adb->num_rows($result) != 0) {
	// ...
}
```

After:
```php
if ($adb->num_rows($result) > 0) {
	// ...
}
```

Before:
```php
if ($adb->getAffectedRowCount($result) == 0) {
	// ...
}
```

After:
```php
if ((int) $adb->getAffectedRowCount($result) === 0) {
	// ...
}
```

# $_FILES

Before:
```php
if ($_FILES[$filename_fieldname]['error'] == 0) {
	// ...
}
```

After:
```php
if ($_FILES[$filename_fieldname]['error'] === UPLOAD_ERR_OK) {
	// ...
}
```

# Other???