Posts about "PHP"

Better error handling in core PHP functions using Safe PHP

Some of the PHP’s core functions are designed in such a way that they do not handle exceptions in a better way. Instead, they just return false if there’s any error. This makes developers to handle those error themselves. Take the example below.

Read More

A deep dive into Generators in PHP

Have you ever stuck in a situation where the code that you’ve wrote uses foreach to iterate over a set of data into an array and which ultimately caused you to exceed a memory? Well, I’ve been to. Many times.

Read More

Get grandparent instance of certain class in PHP

Recently, I stumbled upon a scenario where I had to extend a class. I'm going to explain what issue I had faced and what's the role of using the grandparent instance of the class to overcome that issue in this article.
Read More

A closer look at Invokable classes in PHP

In PHP, Invokables refer to any class that may be instantiated without any constructor arguments. In other words, one should be able to create an instance solely be calling new $className(). To implement an invokable class, one needs to use __invoke() magic method of PHP. Before we understand how invokable exactly works, let’s take a look why invokable classes even exists in PHP.

Read More

PHP 7.4 will support first-class property type declarations

With the introduction of scalar type declaration and return type declaration in PHP 7.0, the language’s type system got improved at some extent. Although it’s great to have some layer of strictness, it’s still missing the support to declare typed properties. But from PHP 7.4, it seems, it’s going to change because according to this accepted RFC, PHP 7.4 will be getting support for first-class property type declarations.

Read More

Packages to make your Laravel development experience awesome.

While developing applications(not necessarily with Laravel), you come across the situation where you need to implement certain functionality. In such cases you shouldn’t want to reinvent the wheel if the functionality is been implemented by someone as a package, accepted well by the community and is ready to be consumed. It’s a no-brainer. I use to follow the same approach and today in this article, I’m going to list out some of my favorite Laravel packages which have made my experience with development in Laravel delicious.

Read More

This is why PHP don't have multiple inheritance

PHP has evolved greatly as a language over years. From a simple functional scripting language which initially started by Rasmus Lerdorf as his hobby project to supporting object oriented programming features PHP has come a long way. Although, PHP has been implementing and improving features of object oriented programming in its every release, there is this one feature which is missing and I’ve always wondered why it is not there in PHP all these years. Yes, I’m talking about multiple inheritance.

Read More

Why you should use Laravel Queues

There comes times when you wouldn’t want your end users staring at white screens or that intimidating loaders for a long time. For instance when user registers to your site, you must have configured your website to send a welcome email or a confirmation email upon registering. So, that operation should be snappy and for that purpose you’d actually want to reduce the amount of time your app takes while sending the email to the user. Laravel Queues comes to the recue for achieving such kind of time consuming tasks.

Read More

Top fetaures of PHP 7.3

PHP development team has just released PHP 7.3 with general availability. This release brings general improvements along with some new features. Even though this is a stable release, the team hasn’t provided concrete migration guide if you want to migrate from the older PHP versions. Maybe they will release those on a later date.

Read More

Array destructuring in PHP

Folks who are familiar with the JavaScript’s ES6 may very well aware of the destructuring feature which allows us to extract data from arrays, objects, maps and sets. For instance, Using ES6 way, we can assign the top level variables of the objects to local variables using destructuring like below:

Read More

Using private repositories as a composer package in PHP

Composer is the goto method of adding dependencies in modern PHP application. You search for a library for a concerned functionality and you’ll probably find the one in the large database of the Pacakgist. But there comes a time where you’d want to use a library which is private and should be only available to you. Well, the good news is, you can achieve this using this trick.

Read More

Laravel - Accessors & Mutators

Accessors and mutators allow you to format Eloquent attribute values when you retrieve or set them on model instances. I’ll explain how you can you use them into your app.

Read More

Laravel Eager Loading - load() Vs. with()

Today, while working with one of my projects(which is built on top Laravel) I bumped into the situation where I needed to get associated model’s data for one of the models. So here, I had two approaches in Laravel to accomplish this which are basically called Eager Loading:

Read More