HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP Keywords : Run a function after each instruction
The declare
keyword sets an execution directive for a block of code. If the declare
statement is not followed by a block then the directive applies to the rest of the code in the
file.
There are three directives which can be declared: ticks
, encoding
and
strict_types
.
The ticks
directive will send a tick event each time a specified number of instructions
have been executed. A tick function can be registered which will run each time a tick event
fires.
The encoding
directive is used to indicate what character encoding the file is using. It
cannot be used on a block, it has to apply to the whole file.
When the strict_types
directive is set, values of the wrong type passed into function
arguments with type hints will throw a fatal error instead of being cast to the correct type.
The enddeclare keyword.
Run a function after each instruction:
<?php
declare(strict_types=1);
function sum(int $a, int $b) {
return $a + $b;
}
// Throws a fatal error because '5' is a string instead
of a number
sum("5", 1);
?>
❮ PHP Keywords