0% found this document useful (0 votes)
4 views3 pages

Understanding PHP Narrow Casting

Narrow casting involves assigning a subclass instance to a superclass reference variable, allowing access to inherited subclass components from the superclass reference. Widening casting assigns a superclass instance to a subclass reference variable, enabling access to all subclass components. Narrow casting is used for dynamic method calls and extending class functionality without changing method signatures, while also avoiding object creation statements.

Uploaded by

Waseem Ahmad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Understanding PHP Narrow Casting

Narrow casting involves assigning a subclass instance to a superclass reference variable, allowing access to inherited subclass components from the superclass reference. Widening casting assigns a superclass instance to a subclass reference variable, enabling access to all subclass components. Narrow casting is used for dynamic method calls and extending class functionality without changing method signatures, while also avoiding object creation statements.

Uploaded by

Waseem Ahmad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NARROW CASTING:

Assigning the instance of subclass to a reference variable of superclass is known as Narrow Cast.
SUPER ([Link]) = SUB (INSTANCE)
Narrow Casting allows us to access the inherited components in subclass from the reference variable of
superclass.
Narrow Cast can also be applied at the time of object creation:
CREATE <obj> SUPER ([Link]) TYPE <sub_class>
WIDENING CASTING
Assigning instance of superclass to a reference variable of subclass is known as Widening Cast.
SUB ([Link])? = SUPER (INSTANCE)
After widening cast we can access back all the components of sub class.
USE:
Narrow casting is used in Dynamic method call.
Allow us to extend the functionality of a class without changing the method signature.
No need to create instances with CREATE OBJECT statement.

You might also like