A well-written PhpDoc is a goldmine of information. It may feel redundant, however, to document values that you use in your code too. Why not parse the PhpDoc itself and use that value? Reflection is the way to go. Consider an Api class that requests users by ID from the Api’s user endpoint. We like […]
Iterators can take the heat out of memory consumption when processing big datasets. Typical for such datasets is that workers process them in manageable chunks of a limited size. As these workers typically are independent of each other, it might be necessary to pack chunks of the source in arrays that can be sent with […]
Some situations in PHP require a set of variables to have values depending on some condition. To achieve such variable-assignment, a switch statement is the traditional GOTO, but PHP’s array syntax combined with the list() language construct.
Keeping Magento shops up to date is important to reduce their vulnerability. Sometimes, security updates introduce breaking changes. The recent Magento update, version 22.214.171.124, includes such a breaking change that can cause blank pages on the front-end and back-end. This is caused by the way in which Magento handles symlinks. When blank pages occur, take […]
PHP provides the array_rand( $arr, $num ) function which returns an integer or array containing the keys of the array. To obtain an array of values the following one-liner can be used: array_intersect_key( $arr, array_flip( array_rand( $arr, $num ) ) ); This picks $num random keys from $arr (array_rand), flips keys with values (array_flip), intersects the […]
A Cron expression validator is created in Laravel 5.3. Laravel provides a versatile and extendable Validation class. Introducing new validations is done by registering a validation function with the extend method on the Validation facade. A Cron expression validator is created by utilising a cron-expression parser. The cron-expression parser used here is the fantastic cron-expression Composer package by Michael […]
Some days ago the Magento security update SUPEE-8788 was released. This update fixes a number of critical vulnerabilities. To fix an existing shop one could either apply the SUPEE-patch or upgrade the shop to Magento 1.9.3. However, after updating I experienced a little issue when trying to reach the shop again. A PHP Exception popped […]
Magento now includes CSRF (Cross-Site Request Forgery) protection on publicly available forms such as the new user registration form. The goal of this is to make it impossible for anyone to POST to an URL without first visiting the corresponding form page. A token is supplied on this page that is sent along with the […]