O’Reilly is giving away some programming ebooks for free. Not the greatest of selections, but might still come handy, as subjects vary from Java and Python to micro-services and software architecture. The books are available in ePub, Mobi, and PDF, but you’ll need to register / login to download them.
Tag: web development
PHP: array_merge_recursive() vs. array_replace_recursive()
Here is a nice blog post describing the important differences between array_merge_recursive() and array_replace_recursive() functions in PHP. These are often overlooked when testing new developments with simpler data structures. Troubleshooting for it later is not too obvious.
GitHub Improvements
GitHub has recently announced a whole lot of improvements to their service and functionality. For me personally the following bits were super exiciting.
Improvements to the code review
Approve or require changes
You’re no longer left on your own to figure out if a comment was important. Or if that emoji means “Go ahead, looks great!” Or “Please no, this is likely going to bring the site down!”
With Reviews, you can leave your comments as suggestions, approve the changes, or request additional changes—on any pull request.
Improvements to the GitHub Profile page
See what’s behind your green squares
GitHub profiles show your life and career as a developer. We’ve taken the contribution graph to new heights with your GitHub timeline—a snapshot of your most important triumphs and contributions.
But there is more – projects, notes, comment drafts, etc. Check the full announcement.
BitBucket Pipelines and Docker for PHP Developers
I’ve been meaning to look into Docker for a long while now. But, as always, time is the issue. In the last couple of days though I’ve been integrating BitBucket Pipelines into our workflow. BitBucket Pipelines is a continuous integration solution, which runs your project tests in a Docker container. So, naturally, I had to get a better idea of how the whole thing works.
“Docker for PHP Developers” article was super useful. Even though it wasn’t immediately applicable to BitBucket Pipelines, as they don’t currently support multiple containers – everything has to run within a single container.
The default BitBucket Pipelines configuration suggests the phpunit/phpunit image. If you want to run PHPUnit tests only, that works fine. But if you want to have a full blown Nginx and MySQL setup for extra bits (UI tests, integration tests, etc), then you might find smartapps/bitbucket-pipelines-php-mysql image much more useful. Here’s the full bitbucket-pipelines.yml file that I’ve ended up with.
MySQL, PHP and “Integrity constraint violation: 1062 Duplicate entry”
Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project:
MySQL was complaining about “Integrity constraint violation: 1062 Duplicate entry”. I had all the necessary safeguards in my code to prevent duplicates in tha column.
I gave up on logic and simply dumped the contents of the problematic column for every record. I found that there was a record with and without an accent on one of the characters. PHP saw each as a unique value, but MySQL did not make a distinction, which is why it complained about a duplicate value. It’s a good thing too, because based on my goal, these should have been treated as duplicates.
She also mentions two possible solutions to the problem:
My solution was to substitute accented characters before filtering duplicates in the code. This way, similar records were rejected before they were sent to the database.
and
As pointed out in the comments, a more robust and versatile solution would be to check the collation on the column.
I’m sure this will come in handy one day.