Learn the basics of PHP.
The most widely used language construct to print output in PHP is echo
. Alternatively, you can also use print
.
The echo
function is faster than the print()
function.
You may use parentheses with the echo
function as echo ("string");
but it isn’t compulsory because echo
isn’t really a function.
Data Types: Null, Boolean, Integer, Float, Array, String
Variable Variables
Operators
arithmetic/ comparison / logical / assignment operators
The spaceship operator (<=>) is a special kind of comparison operator. It
- returns
-1
if first expression is lesser than the second expression. - returns
1
if the first expression is greater than the second expression. - returns
0
if the first expression is equal to the second expression.
Conditional Statements
if-elseif-else, switch statement, ternary statement
Loops
Loops allow a programmer to execute the same block of code repeatedly instead of re-writing code that needs to be executed multiple times.
There are many types of loops:
- while loop
- do…while loop
- for loop
- foreach loop
Functions
In PHP there are two major types of functions:
- Built-in functions
- User-defined functions
In pass by reference, we actually pass the value using ampersand sign &
. The additional &
is very important: it tells the compiler that the data is a reference to the value rather than simply the value itself.
There are two types of variables depending on the scope (or visibility):
- local variables
- global variables
Recursion is a method of function calling in which a function calls itself during execution.
A recursive function must comprise of at least one base case i.e. a condition for termination of execution.
The function keeps on converging to the defined base case as it continuously calls itself.
String /Array
https://www.educative.io/module/page/r0w3pLt4zgmLJ9GA1/10370001/4668278244376576/5858877656793088
Checking the requirements, there are some extensions have to install.
Before getting started, update the PHP version to the latest with Homebrew
brew install php
We did not specify the PHP version to upgrade which defaults to upgrade the latest installed version on our machine.
To be able to run the PHP and PECL CLI commands globally we need to add the /usr/local/bin
and /usr/local/sbin
symlink directories to our PATH environment variable.
Add this to ~/.zshrc
and then run source ~/.zshrc
export PATH="/usr/local/Cellar/php/8.0.13/bin:$PATH"
Now check the Symfony book requirements
➜ desktop symfony book:check-requirements
[OK] Git installed
[OK] PHP installed version 8.0.13 (/usr/local/bin/php)
[KO] PHP extension "redis" not found, optional - needed only for chapter 31
[OK] PHP extension "intl" installed - required
[OK] PHP extension "mbstring" installed - required
[OK] PHP extension "xsl" installed - required
[OK] PHP extension "curl" installed - optional - needed only for chapter 17 (Panther)
[OK] PHP extension "xml" installed - required
[OK] PHP extension "openssl" installed - required
[OK] PHP extension "sodium" installed - required
[OK] PHP extension "ctype" installed - required
[OK] PHP extension "pdo_pgsql" installed - required
[OK] PHP extension "gd" installed - optional - needed only for chapter 23 (Imagine)
[OK] PHP extension "zip" installed - optional - needed only for chapter 17 (Panther)
[KO] PHP extension "amqp" not found, optional - needed only for chapter 32
[OK] PHP extension "json" installed - required
[OK] PHP extension "session" installed - required
[OK] PHP extension "tokenizer" installed - required
[OK] Composer installed
[OK] Docker installed
[OK] Docker Compose installed
[OK] Yarn installed[OK] Congrats! You are ready to start reading the book.
The next step is to create a guestbook repo somewhere
symfony new --version=5.0-1 --book guestbook --debug
but got this error
Update the required version in the composer.json
solved this issue
"require": { "php": "8.0.13"},
This guestbook repository contains all the codes of the book.
symfony new --version=5.2-2 --book guestbook
symfony book:checkout 10