How to check whether a column exists?

Notice: This thread is very old.
ok
Member | 10
+
+1
-

Hi,

I there any way how to check whether a column in ActiveRow exists? Even column of NULL value, so isset() is not applicable.

hacafrakus
Member | 14
+
+1
-

The quick solution I have found is this – it is the same method used internally, since toArray() is just a $data property getter (see https://api.nette.org/…Row.php.html#272).

if (array_key_exists('columnName', $row->toArray())) {
	// ...
}

Or using exceptions.

try {
	$row->columName;
	// ... exists ...
}
catch (Nette\MemberAccessException $e) {
	// ... does not exist ...
}