
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

392 Views
In PHP 8, fdiv() function is used to perform floating-point division on IEEE 754 standard. fdiv() is a mathematical operation that divides two numbers and returns a floating-point number.The fdiv() function works similar to the intdiv() and fmod() function, which allows division by zero. Instead of showing an error, the fdiv() function returns INF, -INF or NAN, when a number is divided by zero.INF (Infinity or real number) – It is the result of a numerical calculation that is mathematically infinite.-INF (Negative Infinite) – it is a negative infinite number or a number below -1.796E308.NAN (Not a Number) – it ... Read More

392 Views
In the earlier versions of PHP, if we wanted to get the type of a variable, we used to employ the gettype() function. This function returns the type of a variable in the custom of a string. It returns all possible values like integer, string, array, boolean, double, resource, NULL, unknown type, etc.However, there were issues in the gettype function. It does not return native and familiar type names. It returns double instead of float and integer instead of int, and so on.To overcome this problem, PHP 8 uses the get_debug_type function.get_debug_type() functionIn PHP 8, the get_debug_type function returns the ... Read More

262 Views
str_starts_with and str_ends_with function are added in PHP 8 to check if a given string starts or ends with another string or not. If it starts and ends with another string, it returns true, otherwise false.Examplestr_starts_with('hello haystack', 'hello'); //starts string found 'True' str_starts_with('hello haystack', 'stack'); //ends string found 'True'str_starts_with('hello haystack', 'hay'); //starts string found 'False' str_starts_with('hello haystack', 'hay'); //ends string found 'False'str_starts_with() function in PHP 8This function checks if a given string starts with the string needle. It returns true if the first string is found, otherwise false.str_starts_with(string $haystack, string $needle): boolExample : using str_starts_with() function.OutputString starts with 'hello'Note: If ... Read More

3K+ Views
In PHP 8, str_contains function determines if a string contains a given substring anywhere. The str_contains function checks if a first-string is contained in the second string and it returns a true /false Boolean value based on whether the string is found or not. it is a self-explanatory function.str_contains(string $haystack, string $needle): boolExample1 : PHP 8 str_contains function.Outputstring(23) "Tutorial has been found"Example: str_contains function.Note: The above program returns false because the first string does not contain the second string.strpos() functionIn PHP 7.x, strops() function is used to check if a given string contains another string or not. This function returns ... Read More

436 Views
Weak Maps were added in PHP 7.4. It can be used to remove or delete objects when the cache refers to objects entity classes. It references to those objects, which does not avoid objects from memory garbage collected. In PHP 8, weak maps allow us to store random data linked to objects, without leaking any memory.In other words, a weak map in PHP 8 is a group of objects in which keys weakly reference. A weak map uses a class to create an object which can be used as a key, which can help to remove and destroy the weak ... Read More

2K+ Views
Trailing commas are being used in PHP since PHP 7.2 version. We can use trailing commas in the last item in the array. We can add the element of the array without modifying the last line of the item if the line is already using a trailing comma.Trailing Commas before PHP 8.0Before PHP 8, we were not able add a comma to the end of the last parameter.Examplefunction($x, $y, $z){ }In PHP 8.0In PHP 8, we can add trailing commas at the end of the last parameter. PHP 8 allows using the trailing commas in the parameter list and Closure ... Read More

462 Views
In PHP 8, a new Stringable Interface (__toSting) is added. This method starts with the double underscore (__). The __toString method allows getting an object represented as a string. When a class defines a method using __toString, then it will call an object whenever it needs to treat as a string.Example: Stringable Interface using __toString Live DemoOutputEmployee NameIn PHP 8, the Stringable interface makes it easy to pass strings. A Stringable interface adds automatically once a class implements the __toString method. It does not require implementing the interface explicitly. The Stringable interface can be helpful for type hinting whenever strict types ... Read More

1K+ Views
PHP 8 uses nullsafe operator instead of a null check condition. Using the nullsafe operator, we can use a chain of calls. While evaluating the elements, if one chain element fails, then the execution of the entire chain will abort and it evaluates to null.When the left-hand side operator evaluates to null, then the whole chain of execution will stop and it evaluates to null. If it does not evaluate to null, then it will behave like a normal operator.The nullsafe operator can be chained, and the expression will be short-circuited from the first nullsafe operator that meets null.$employee->getDepartment()?->getAddress()->format();The nullsafe ... Read More

772 Views
Match expression is a new feature that is added in PHP 8. It is very much similar to switch-case statements, but it provides more safe semantics.Match expression does not use the 'case and break' structure of switch-case statements. It supports joint conditions, and it returns a value rather than entering a new code block.We can store match results in a variable because it is an expression.Match expression does not need a break statement like a switch. It supports only single-line expression.Example: PHP 7 Using Switch Statement Live DemoOutputHello World!Example: Above PHP 7 Code Using PHP 8 Match ExpressionOutputLooks Good!Example: Using PHP ... Read More

777 Views
In PHP 8, Constructor Property Promotion is added. It helps to reduce a lot of boilerplate code while constructing simple objects. This feature allows us to combine class fields, constructor definition, and variable assignments, all in one syntax, into the constructor parameter list.We can say that instead of specifying class properties and a constructor, we can combine all of them using constructor property promotion.Example 1: PHP 7 CodeExample 2: PHP 8 codeWe can re-write the above PHP 7 code in PHP 8 as follows −Output10.9 20 30.8In the above code, we combined property definition and population inline in the constructor ... Read More