1. Some PHP closing tag information -
We can skip adding closing tag if only writing PHP code. But while writing with other languages, ex - HTML, we must need to add closing tag.
Semicolon in the last line of PHP can be omitted. For example.
<?php
echo "Hi"; // semicolon needed here
echo "hello" // semicolon can be omitted here
?>
2. We can enable strict mode in php by writing
declare('strict_type=1)
This will enable strict type checking in php. For instance, usually php convert a number to a number if it is written like this '2'. But if we enable strict_type then it won't do this. It is better to keep enabled strict_type to avoid some bugs, specially if we are doing some kind of calculation type of functionality.
3. Callable is a type which make a varibale or function callable. We can send it as a function argument type in a function.
function printName( callable $callable) {
if(is_callable($callable)){
$callable('forhad');
}
}
$callableFunction = function ($name) {
echo $name;
};
printName($callableFunction);
printName(function ($name) {
echo "<br/> this is a new callable function";
});
copyright forhad