Why does PHP not complain when I treat a null value as an array like this?

There are three types which it might be valid to use the array derefence syntax on: Arrays Strings (to access the character at the given position) Object (objects implementing the ArrayAccess interface) For all other types, PHP just returns the undefined variable. Array dereference is handled by the FETCH_DIM_R opcode, which uses zend_fetch_dimension_address_read() to fetch … Read more

Rails: Order with nulls last

I’m no expert at SQL, but why not just sort by if something is null first then sort by how you wanted to sort it. Photo.order(‘collection_id IS NULL, collection_id DESC’) # Null’s last Photo.order(‘collection_id IS NOT NULL, collection_id DESC’) # Null’s first If you are only using PostgreSQL, you can also do this Photo.order(‘collection_id DESC … Read more

Redefining NULL

The C standard does not require null pointers to be at the machine’s address zero. HOWEVER, casting a 0 constant to a pointer value must result in a NULL pointer (ยง6.3.2.3/3), and evaluating the null pointer as a boolean must be false. This can be a bit awkward if you really do want a zero … Read more

How to do unique constraint works with NULL value in MySQL

No, MySQL is doing the right thing, according to the SQL-99 specification. https://mariadb.com/kb/en/sql-99/constraint_type-unique-constraint/ A UNIQUE Constraint makes it impossible to COMMIT any operation that would cause the unique key to contain any non-null duplicate values. (Multiple null values are allowed, since the null value is never equal to anything, even another null value.) If you … Read more