Definition and UsageCallback is a pseudo-type in PHP. With PHP 5.4, Callable type hint has been introduced, which is similar to Callback. When some object is identified as callable, it means that it can be used as a function that can be called. A callable can be a built-in or user defined function or a method inside any class.The is_callable() function can be used to verify if the identifier is a callable or not. PHP has call_user_function() that accepts a function's name as a parameter.Following example shows a built-in function is a callable.Example Live DemoOutputThis will produce following result −bool(true)In following ... Read More
Definition and UsageThis is one of the scalar data types in PHP. A boolean data can be either TRUE or FALSE. These are predefined constants in PHP. The variable becomes a boolean variable when either TRUE or FALSE is assigned.SyntaxResult of echoing TRUE value displays 1 while for FALSE it shows nothing. Using var_dump() function displays bool as type with valueBoolean constants are not case sensitive. That means TRUE is equivalent to true and FALSE is similar to FalseLogical operators return boolean valueCastingAny data type can be explicitly converted to boolean with the help of casting operator (bool) or (boolean), ... Read More
Definition and UsageA PHP code script is a text file having .php extension and is stored on web server. The PHP parser on server looks for special sequence of characters . These are called PHP's opening and closing tags. Statements witihn these two are interpreted by the parser. PHP script within these tags can be embedded in HTML document, so that embedded code is executed on server, leaving rest of the document to be processed by client browser's HTML parser.SyntaxShort tagsPHP allows a using a shorter representation of opening tag PHP VersionThis setting is recommended to be Off for production ... Read More
Definition and UsagePHP file can have mixed content with code within tags embedded in a HTML document. Code outside tags is ignored by the parser, leaving it to be interpreted by client browser. A HTML document can have multiple blocks of PHP, each inside tags.Syntax HTML block HTML block HTML block Every time opening PHP tag is encountered, parser starts rendering the output to the client until closing tag is reached. If code consusts of conditional statement, th parser determines which block to be skipped.Again till another opening tag comes, everything is treated ... Read More
Get-Error cmdlet was introduced in PowerShell v7. It displays the most recent error messages from the current session.When you check the get member of this command, its output is in the form of PSExtendedError so whatever the output is produced by this command is in a detailed manner and so this command is very helpful in troubleshooting error messages.PS C:\> Get-Error | gm TypeName: System.Management.Automation.ErrorRecord#PSExtendedErrorWe will write one command in the PowerShell console which is ultimately generate an error.PS C:\> Get-ChildItem c:otexist Get-ChildItem: Cannot find path 'C:otexist' because it does not exist.The above directory does not exist. Let’s get a ... Read More
IntroductionPrecedence of operators decides the order of execution of operators in an expression. For example in 2+6/3, division of 6/3 is done first and then addition of 2+2 takesplace because division operator / has higher precedence over addition operator +. To force a certain operator to be called before other, parentheses should be used. In this example, (2+6)/3 performs addition first, followed by division.Some operators may have same level of precedence. In that case, the order of associativity (either left or right) decides the order of operations. Operators of same precedence level but are non-associativem cannot be used next to ... Read More
IntroductionC style increment and decrement operators represented by ++ and -- respectively are defined in PHP also. As the name suggests, ++ the increment operator increments value of operand variable by 1. The Decrement operator -- decrements the value by 1. Both are unary operators as they need only one operand. These operators (++ or --) can be used in prefix or postfix manner, either as an expression or along with other operators in a more complex expression.Syntax$x=5; $x=5; $y=5; $x++; //postfix increment $y--; //postfix decrement ++$y; //prefix increment --$x; //prefix decrementWhen used independently, postfix and prefix increment/decrement operator ... Read More
IntroductionThere is one Execution operator defined in PHP. A string inside back-ticks (``) is treated as a DOS command (a shell command in UNIX/Linux) and its output is returned. This operator is similar in operation to shell_exec() function in PHP.Following code executes DIR command and returns result as string.ExampleOutputFollowing result will be displayedVolume in drive C is Windows 10 Volume Serial Number is 540D-CE99 Directory of C:\xampp\php 01/27/2016 05:32 PM 18, 869 CompatInfo.php 07/08/2020 06:40 PM 64 test.php 07/11/2020 02:13 PM 48 testscript.php 03/30/2013 05:59 PM 1, 447 webdriver-test-example.php 4 File(s) 20, 428 bytes 0 Dir(s) 178, 002, 157, 568 ... Read More
$Errorview variable determines the display format of the error message in PowerShell. Before PowerShell 7 there were mainly two views, Normal View (Default view)Category ViewWith PowerShell version 7, one new additional error view category is included and now there are 3 $ErrorView categories for version 7.Concise View (Default)Normal ViewCategory ViewWe will understand each view one by one.A ) Normal ViewIt is the default view before PowerShell version 7 and it produces the detailed multiline errors and bit noisy. It includes the exception name, category, line number of the error, etc.$ErrorView = 'NormalView' Get-ChildItem C:\NoDirectoryOutputGet-ChildItem : Cannot find path 'C:\NoDirectory' because ... Read More
IntroductionIn PHP @ symbol is defined as Error Control Operator. When it is prefixed to any expression, any error encountered by PHP parser while executing it will be suppressed and the expression will be ignored.Following code tries to open a non-existing file for read operation, but PHP parser reports warningExample Live DemoOutputFollowing result will be displayedHello World PHP Warning: fopen(nosuchfile.txt): failed to open stream: No such file or directory in /home/cg/root/1569997/main.php on line 2Prepending @ symbol to fopen() expression suppresses error message and statement itself is ignoredExample Live DemoOutputFollowing result will be displayedHello World