php8.5
Home/ Manual/ uopz / functions/ uopz_extend

uopz_extend

PHP function Edit on GitHub ✎

(PECL uopz 1, PECL uopz 2, PECL uopz 5, PECL uopz 6, PECL uopz 7 < 7.1.0)

Extend a class at runtime

Description

uopz_extend(string $class, string $parent): bool

Makes class extend parent

Parameters

class

The name of the class to extend

parent

The name of the class to inherit

Return Values

Success

Errors/Exceptions

As of PHP 7.4.0, uopz_extend() throws a RuntimeException, if OPcache is enabled, and the class entry of either class or parent (if it is a trait) is immutable.

Examples

uopz_extend() example

php
<?php
class A {}
class B {}

uopz_extend(A::class, B::class);

var_dump(class_parents(A::class));
?>

The above example will output:

output
array(1) {
  ["B"]=>
  string(1) "B"
}

Source: reference/uopz/functions/uopz-extend.xml · from the official PHP manual (php/doc-en)