I’ve recently been updating a website that was written a long time ago that has not been touched in a meaningful way in many years. In addition to the actual work I was asked to do, I took the opportunity to update the password hashing routines.
This site is so old that the passwords are stored using MD5 hashes. and that’s not really good enough today. So I included updating to bcrypt hashing with password_hash() and password_verify() in my statement of work.
Last chapter of this series. If you have followed along with these blog posts you are now fully capable of creating projects using the Object Oriented paradigm.
In this part, we will learn how to use abstract classes and several other less common features of PHP such as reflection APIs and the singleton design pattern.
First Round: Basic PHP Interview Questions and Answers
Q1. Describe PHP
Ans: PHP is a server-side scripting language whose most common use is in web applications. PHP comes with various frameworks and CMSs that help create websites. Being object-oriented, PHP resembles languages such as Java and C#, which makes it very easy to learn and implement. A few of the popular applications built on PHP are WordPress and osCommerce.
Q2. Show What Use “echo” has in PHP
Ans: The main purpose of echo in PHP is to help print data in the webpage. For example, the following code prints the text for this item from the webpage:
Now I work with more programming languages, I start to miss features from other languages when I come “home" to PHP. One that I hadn’t seen in PHP before I saw it in other languages such as Node.js (I think Ruby had the original implementation) was: a way to easily control setting your environment variables, particularly in development. In Node.js, the dotenv library is great for this; handily in PHP vlucas has already created phpdotenv so we are all set to apply these tricks to PHP applications!
Managing Environment Variables
The overall idea is that your code can read variables from a local text file rather than from the actual environment variables. This makes it easier to switch projects because you can write a file per project and not have to re-export environment variables (or wonder why the variables are wrong if you didn’t start a new shell when switching projects). Also since I often write code for other people to use, such as example applications or starter kits, the .env file provides a clear list of the values they need to set for the thing to work.
Recently I needed to test part of Slim that uses the built-in PHP functions header() and headers_sent(). To do this, I took advantage of PHP’s namespace resolution rules where it will find a function within the same namespace first before finding one with the same name in the global namespace. The idea of how to do this came courtesy of Matthew Weier O’Phinney where this approach is used for similar testing in Zend-Diactoros.
This is the relevant part of the code I want to test:
Once upon a time, there was a web developer who used to spend weeks and weeks updating the same lines of code. This gave him very bad headaches. One day, while browsing blog posts, he came across the words Object-Oriented Programming and what happened next is astonishing…
In the previous post, you discovered the basics of the OOP paradigm in PHP, from its simple syntax to the advantages of reusing the same code in a straightforward but still powerful way.
Learning object-oriented-programming is one if not the most valuable skills a web developer can learn.
For instance, there are places, like London, that are so competitive that you must have OOP among your abilities in order to get a job as a PHP Developer.
Follow the Series
This blog post is the fourth and last part of the”Definitive Guide to Your Next PHP Framework" series.
If you did not read it yet, you can check the other blog posts following the links:
Symfony is a PHP model-view-controller framework used to develop web applications. The main reasons Symfony has gained fame among the developer community are its database engine compatibility, its faster development, and its robust system. These features make it easy to develop and customize web applications.
To make your web application successful, you should consider how user experience is affected by the inevitable errors that pop up in production. Customers can walk away from a purchase or churn out from a subscription when applications do not run properly. A fast response to critical problems is essential. To minimize customer impact, it is important to track and fix issues quickly.
The following are some of the new features PHP 7:
Scalar type declarations