Programming Articles

Page 28 of 2546

PHP References

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 5K+ Views

In PHP, references enable accessing the same variable content by different names. They are not like pointers in C/C++ as it is not possible to perform arithmetic operations using them. In C/C++, they are actual memory addresses. In PHP in contrast, they are symbol table aliases. In PHP, variable name and variable content are different, so the same content can have different names. A reference variable is created by prefixing & sign to original variable. Assign By Reference You can create a reference by using the & operator. When you assign $b = &$a, both variables point to ...

Read More

PHP Visibility modes

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 3K+ Views

In PHP, visibility modes control the accessibility of class members (properties, methods, and constants). PHP provides three visibility keywords: public, private, and protected. Public members are accessible from anywhere, protected members can be accessed within the class and its subclasses, while private members are only accessible within the same class. Class public protected private ✓ Accessible everywhere ✓ Class + Subclasses only ...

Read More

PHP Late Static Bindings

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 343 Views

Late static binding in PHP allows you to reference the called class in a static inheritance context rather than the class where the method is defined. When using static:: instead of self::, PHP resolves the class name at runtime based on the calling context. The Problem with self:: When static methods use self::, the class reference is resolved at compile time to the class where the method is defined ? name of class: test1 The output shows the parent class name because self:: was resolved to test1 at compile time. ...

Read More

PHP Object Serialization

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 1K+ Views

Object serialization in PHP converts an object into a string representation (byte-stream) that can be stored or transmitted. The serialize() function creates this string containing all object properties, while unserialize() reconstructs the object from the string. Syntax // Serialize an object $serialized_string = serialize($object); // Unserialize back to object $object = unserialize($serialized_string); Basic Example Let's create a simple class and demonstrate serialization − Serialized: O:6:"Person":2:{s:11:"Personname";s:5:"Alice";s:10:"Personage";i:25;} Name: Alice Age: 25 Storing Serialized Objects in Files You can save serialized objects to files for persistent ...

Read More

PHP Scope Resolution Operator (::)

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 7K+ Views

In PHP, the double colon :: is defined as Scope Resolution Operator. It is used when we want to access constants, properties and methods defined at class level. When referring to these items outside class definition, name of class is used along with scope resolution operator. This operator is also called Paamayim Nekudotayim, which in Hebrew means double colon. Syntax 3.142103.14210 Using self Keyword Inside Class To access class level items inside any method, keyword self is used − 3.142 10 Accessing ...

Read More

PHP Objects and references

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 4K+ Views

In PHP, objects are passed by references by default. Here, reference is an alias, which allows two different variables to write to the same value. An object variable doesn't contain the object itself as value. It only contains an object identifier which allows access to the actual object. When an object is sent by argument, returned or assigned, the different variables are not aliases − instead, they hold a copy of the identifier, pointing to the same object. Object Assignment PHP has spl_object_hash() function that returns unique hash ID of an object. In the following code, two object ...

Read More

PHP Magic Methods

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 10K+ Views

Magic methods in PHP are special methods that are automatically called when certain conditions are met. These methods are named with double underscore (__) as prefix and must be declared public. They act as interceptors that provide dynamic behavior to your classes. Object Access Magic Methods __get() and __set() These methods handle access to inaccessible or non-existing properties − John __isset() and __unset() These methods handle isset() and unset() calls on inaccessible properties − bool(true) bool(false) String and Function Magic ...

Read More

PHP Autoloading Classes

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 3K+ Views

In PHP, you can use classes from other files without explicitly including them by using autoloading. When PHP encounters an undefined class, it automatically attempts to load the class file if it's registered with the spl_autoload_register() function. Syntax spl_autoload_register(function ($class_name) { include $class_name . '.php'; }); The class will be loaded from its corresponding .php file when it's first used for object instantiation or any other class operation. Basic Autoloading Example Here's how to register a class for autoloading ? test1 object created ...

Read More

PHP Declaring sub-namespaces

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 350 Views

PHP allows creating nested namespaces, similar to how directories contain subdirectories in a file system. Sub-namespaces are declared using the backslash character \ to define the hierarchical relationship between parent and child namespaces. Syntax To declare a sub-namespace, use the following syntax ? namespace ParentNamespace\ChildNamespace; Example Here's how to create and use sub-namespaces with functions ? Hello World from space1 Hello World from space2 Using the 'use' Keyword You can import sub-namespaces with the use keyword for cleaner code ? ...

Read More

PHP Name Resolution Rules

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 291 Views

In PHP, namespace resolution follows specific rules that determine how the interpreter locates classes, functions, and constants. Understanding these rules is crucial for writing maintainable code with proper namespace organization. Types of Namespace Names PHP recognizes three types of namespace identifiers − Unqualified names − Names without namespace separator (\). They refer to the current namespace. Qualified names − Names containing separator symbol like myspace\space1. These resolve to subnamespaces. Fully qualified names − Names starting with \ character like \myspace\space1. These resolve to absolute namespaces. Resolution Rules Unqualified Names Names without separators ...

Read More
Showing 271–280 of 25,451 articles
« Prev 1 26 27 28 29 30 2546 Next »
Advertisements