PHP Idioms

Coding practices you will see in recent versions of Zen Cart

This document is intended to capture PHP changes that some developers may find unclear because they differ from what was done in the past. Some but not all are driven by PHP8 changes.

The use of ===:

This comparison operator means “equal to and of the same type.” It has become more important in PHP8+ which does stricter comparisons.

See the PHP documentation on Comparison Operators for more details.

The use of ??

This operator (null coalescing) checks that the first operand exists and is not null. If so, it returns the first operand; otherwise, it returns the second operand.


$enddate = zen_db_input($_REQUEST['end_date'] ?? date('Y-m-d'));

is the same as:

if (!empty($_REQUEST['end_date'])) { 
   $enddate = zen_db_input($_REQUEST['end_date']); 
} else {
   $enddate = date('Y-m-d');

See the PHP documentation on Null coalescing operator for more details.

Missing PHP close tag ?> at the end of a file

The close tag ?> is not recommended at the end of a file, and should be left off.

Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified June 19, 2022 by Scott C Wilson (edb9b78).