Skip to content

Php-bug in CRMEntity, function insertIntoEntityTable

There seems to be a Php-bug in CRMEntity, function insertIntoEntityTable, if ($uitype == 56)

if (isset($this->column_fields[$fieldname])) {
	if ($uitype == 56) {
	//	if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) { // php-bug. Returns true when $this->column_fields[$fieldname] = 0
		if ($this->column_fields[$fieldname] === 'on' || $this->column_fields[$fieldname] == 1) {
			$fldvalue = '1';
		} else {
			$fldvalue = '0';
		}
	}

Testing php:

//	When $this->column_fields[$fieldname] = 0:
	$test0 = $this->column_fields[$fieldname] == 'on' ? 'true' : 'false';			// true - Wrong! (php-bug)
	$test1 = $this->column_fields[$fieldname] === 'on' ? 'true' : 'false';			// false - Correct
	$test2 = (string)$this->column_fields[$fieldname] == 'on' ? 'true' : 'false';	// false - Correct
	$test3 = $this->column_fields[$fieldname] == 1 ? 'true' : 'false';				// false - Correct