Skip to content

Chapter 3 of 38

Basic Syntax and Structure

Understand tags, statements, expressions, output, includes, strict types, and files.

28 minutes 10 quick checksBy Subha Prasad
Lesson 3 of 38Course navigation

Lesson content

Read, practise, then check your understanding

PHP begins with <?php; pure PHP files normally omit the closing tag. Statements end with semicolons, braces form blocks, and declarations should be organized through Composer autoloading rather than large include chains.

Practical example

<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/vendor/autoload.php';
function greeting(string $name): string { return "Hello, $name"; }
echo greeting('Mira');

require fails when a file is absent; include warns and continues. Strict types is per-file and affects scalar calls originating there. Separate bootstrap, domain logic, templates, configuration, and HTTP response handling.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes PHP opening tag?
Which PHP term matches this description: The <?php marker entering PHP code.
Which statement best describes statement?
Which PHP term matches this description: An executable instruction commonly terminated by a semicolon.
Which statement best describes expression?
Which PHP term matches this description: Code evaluated to a value.
Which statement best describes declare strict_types?
Which PHP term matches this description: A per-file directive enabling strict scalar argument checks for calls from that file.
Which statement best describes echo?
Which PHP term matches this description: A language construct writing one or more strings to output.

0 of 10 checks passed

Your progress is saved on this device.