PHP Articles

Page 23 of 81

Reading Attributes with Reflection API in PHP 8

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 721 Views

In PHP 8, the Reflection API provides powerful methods to read attributes from classes, methods, properties, functions, and parameters. The getAttributes() method returns an array of ReflectionAttribute objects that allow you to inspect attribute names, arguments, and instantiate attribute instances. Syntax The getAttributes() method is available on all Reflection objects ? public function getAttributes(?string $name = null, int $flags = 0): array Parameters $name − Optional attribute class name to filter by $flags − Flags to control attribute retrieval behavior Example Here's how to read attributes from a function using the ...

Read More

Number comparisons in PHP 8

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 375 Views

PHP 8 introduced significant changes to number comparisons, making them more consistent and predictable. When comparing values, PHP 8 uses number comparison for numeric types, but converts numbers to strings for string comparisons, following stricter rules. String Categories Strings can be categorized in three ways − Numeric string − Contains only numeric characters. Example − "1234" or "1.24e1". Leading-numeric string − Starts with numeric characters followed by non-numeric characters. Example − "12xyz" or "123 " Non-numeric string − Cannot be interpreted as numeric. Example − "foo" or "abc123" PHP 7 vs PHP 8 Comparison ...

Read More

Uniform variable syntax in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 529 Views

In older versions of PHP, variable syntax was inconsistent and could be confusing. For example, expressions like ${$first['name']} created ambiguity in parsing order. PHP 7 introduced Uniform Variable Syntax to resolve these inconsistencies by enforcing left-to-right evaluation. The uniform variable syntax evaluates variables from left to right and requires proper use of curly brackets for clarity − echo ${$first['name']}; This syntax allows new combinations of operators but may break backward compatibility in expressions that relied on older evaluation patterns. Function Expression Example With uniform variable syntax, you can immediately invoke function expressions − ...

Read More

Unicode codepoint escape syntax in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 749 Views

PHP 7 introduced Unicode codepoint escape syntax, allowing you to write Unicode characters directly in double-quoted strings using the \u{xxx} format. This syntax accepts hexadecimal codepoints of varying lengths (2, 4, 6, or more digits) and produces UTF-8 character output. Syntax The Unicode escape syntax follows this pattern − "\u{hexadecimal_codepoint}" Leading zeros are optional, so \u{aaa} and \u{0000aaa} produce the same result. Basic Example Here's how to use Unicode codepoints in PHP 7 − પપ香 Right-to-Left Text Example Some languages like Hebrew and ...

Read More

Display array structure and values in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 14K+ Views

An array in PHP is a data structure that can store multiple elements under a single variable. To display array structure and values in PHP, we can use print_r() or var_dump() functions to show array contents in human-readable format. Using print_r() The print_r() function displays variable information in a human-readable format, showing array keys and elements clearly − Array ( [x] => Dept [y] => Employee [z] => Array ( ...

Read More

Preg_replace_callback_array() in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 328 Views

The preg_replace_callback_array() function in PHP 7 performs pattern matching and replacement using multiple regular expressions with their corresponding callback functions. This function allows you to apply different callbacks for different patterns in a single operation. Syntax preg_replace_callback_array(patterns, subject, limit, count, flags) Parameters patterns − An associative array mapping regular expression patterns to callback functions. subject − The input string or array of strings to perform replacements on. limit − Optional. Maximum number of replacements for each pattern. Default is -1 (unlimited). count − Optional. Variable that will contain the number of replacements performed. ...

Read More

Generator Return Expressions in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 444 Views

In PHP 7, generator functions can now return expressions using the return statement. This enhancement allows generators to yield values during iteration and then return a final value when the generator completes execution. Key Features Generator return expressions in PHP 7 provide the following capabilities − Return a final value from a generator function after all yields are completed Retrieve the returned value using the Generator::getReturn() method Only expression values can be returned, not references The return value is accessible once the generator has finished yielding all values Basic Example Here's a simple ...

Read More

Group Use declarations in PHP 7

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 982 Views

In PHP 7, Group Use declarations provide a more readable way to import classes, constants, and functions from the same namespace. This feature reduces code verbosity and makes it easier to identify multiple imported entities that belong to the same module. Group Use declarations allow you to import multiple structures from a namespace in a single statement, eliminating redundant code and improving maintainability. Syntax The basic syntax for Group Use declarations is − use namespace\{ClassA, ClassB, ClassC}; use function namespace\{function1, function2, function3}; use const namespace\{CONST1, CONST2, CONST3}; Before PHP 7 (Traditional Approach) ...

Read More

Difference Between For and Foreach in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 5K+ Views

In this post, we will understand the differences between for and foreach loops in PHP − The 'for' Loop It is an iterative loop that repeats a set of code till a specified condition is reached. It is used to execute a set of code for a specific number of times. Here, the number of times is controlled by the iterator variable. Syntax for( initialization; condition; increment/decrement ) { // code to iterate and execute } Initialization: It is used to initialize the iterator variables. It also helps ...

Read More

Difference Between PHP and JavaScript

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 15-Mar-2026 8K+ Views

JavaScript and PHP are two of the most widely used programming languages for web development. PHP is primarily a server-side scripting language that handles backend operations, while JavaScript is a client-side scripting language that manages frontend interactions and user experiences. Since PHP is derived from the C programming language, it is relatively easy to learn for developers with a solid foundation in C. Both languages serve different purposes in web development, each with unique advantages and specific use cases. What is PHP? PHP is a general-purpose scripting language primarily designed for web development. Created in 1994 by ...

Read More
Showing 221–230 of 802 articles
« Prev 1 21 22 23 24 25 81 Next »
Advertisements