How to start learning PHP: features, syntax and ideas for the first projects
Getting Started with PHP: Features, Syntax, and Ideas for Your First Projects Main Image
In this article, we will understand the prospects and popularity of PHP in 2022, consider the pros and cons of the language, talk about platforms for practicing skills in practice and sources of ideas for the first projects.
PHP is the most popular web development language. Almost 80% of all websites on the Internet are written in this language.
Because the language is so widely spoken, jobs can be found in almost every field. It is especially relevant in companies at the stage of creating an mvp (minimum viable product) or among developers of CRM systems.
The PHP code looks like this:
$length = strlen($password);
return $length > 8 && $length < 20;
isCorrectPassword(‘qwerty’); // false
isCorrectPassword(‘qwerty1234’); // true
isCorrectPassword(‘zxcvbnmasdfghjkqwertyui’); // false
Benefits and features of PHP
The community helps with problems that cannot be solved by reading the documentation and Google. PHP has a large and beginner-friendly
The largest global programming language forum is PHP Community – PHP Club. There are several dozen large telegram chats for developers of different levels (the most popular: one, two, three), as well as separate chats for juniors, where you can ask any questions and not be afraid of condemnation.
Low entry threshold
This is both a plus and a minus of the language. On the one hand, it is relatively easy to start programming in PHP, on the other hand, some developers do not go beyond the CMS, work at the constructor level and rarely touch the code. The community suffers from this, and finding a PHP developer who understands the theory and knows how to code becomes a really difficult task.
Create your first resume:
You can publish your resume for free in our Hexlet-CV service and get advice on how to improve it from developers and HR managers
Backward compatibility is a term that refers to the ease of updating code to a new version. PHP developers are trying to keep it at a high level: by the time the eighth version is released, the language is almost completely backward compatible (except for some points).
This is both an advantage and a disadvantage of a programming language: on the one hand, developers can not be afraid of moving and always use the new version. On the other hand, PHP still has some standard library functions that work strangely and inconsistently. A striking example is the array map and array reduce functions, in which the position of the input array and function are different. It’s not obvious and you have to get used to it.
Let’s start with the basics: the string Hello, world! can be displayed in two ways.
Using the special echo command
echo ‘Hello World!’;
// => Hello World!
Using the print_r() function.
// => Hello World!
Any PHP code must be wrapped in a <?php ?> construct, where <?php is the opening tag and ?> is the closing tag. This is a feature of the programming language.
There are two types of comments in code: single-line (//) and multi-line (/* */).
* The night is dark and
*full of terrors.
print_r(‘I’m the King’);
You do not need to specify its type before declaring a variable – just put the $ sign. In addition, one value can be assigned to several variables.
Here is a description of other syntax elements in PHP: types, arrays, arithmetic operations, loops, if-else conditions, functions.
Frameworks for PHP
PHP has many frameworks, but in this article we’ll take a quick look at three of the most popular: Laravel, Yii, and Symfony.
Laravel is a framework with the lowest entry threshold, you can start exploring the features of the language from it. If difficulties arise, there are several chats on the framework: for basic questions and for more difficult cases.
Yii is another framework with a low barrier to entry: to get started with it, it is enough to know PHP at the beginner level. hats are divided into versions: the first, second and third.
Symfony is the largest PHP framework library. There are more opportunities, but the entry threshold is higher.
What to learn with PHP
PHP is a web development language, so knowing HTML and CSS at least at a basic level is a must. The same applies to the HTTP protocol at the level of understanding the process of client-server requests.
Other technologies can be divided into two categories:
Good to know. Git (needed by all programmers who are going to engage in commercial development), SQL (the vast majority of web applications have a database), Nginx and Apache (for setting up the environment);
How to choose a code editor or PHP development environment
At the first stage, a complex development environment like PHPStorm is not needed – for a beginner, the IDE will seem like a monster with many features, which is also slow to open.
Sublime and VSCode, on the other hand, are quick to open, set up, and make it relatively easy to plug in additional features. For example, tools for interacting with a database or with a cache.
When you need tools to work with Git, template engines, environments, tests, and other technologies, you can switch to IDEs such as PHPStorm, Netbeans, and Aptana Studio.
What books and sites to use to learn PHP
It has already been said above that when learning PHP, it is important to pay a lot of attention to theory, and not just learn to write code. This programming language gives a very vague idea of how its components work at a basic level. Understanding the theory will help you master both PHP and any other programming language.
There are several suitable books:
“Groaming algorithms. An Illustrated Guide for Programmers and the Curious, Aditya Bhargava;
“Code: The Secret Language of Computer Science” by Charles Petzold;
“Clean Code”, “Ideal Programmer”, “Clean Architecture”, Robert Martin.
It is important to clarify that it is better to read these books six months after the start of training. On the one hand, during this time, an understanding of PHP will appear, on the other hand, the desire to apply new knowledge and rewrite the entire project will not arise immediately.
Speaking of websites, PHP: The Right Way has an extensive database of materials for developers of different levels, and CodeBasics is suitable for learning syntax.