略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: uopz_compose

2024-11-13

uopz_compose

(PECL uopz 1, PECL uopz 2)

uopz_composeCompose a class

警告

This function has been REMOVED in PECL uopz 5.0.0.

说明

uopz_compose(
    string $name,
    array $classes,
    array $methods = ?,
    array $properties = ?,
    int $flags = ?
): void

Creates a new class of the given name that implements, extends, or uses all of the provided classes

参数

name

A legal class name

classes

An array of class, interface and trait names

methods

An associative array of methods, values are either closures or [modifiers => closure]

properties

An associative array of properties, keys are names, values are modifiers

flags

Entry type, by default ZEND_ACC_CLASS

返回值

范例

示例 #1 uopz_compose() example

<?php
class myClass {}
trait 
myTrait {}
interface 
myInterface {}

uopz_compose(
    
Composed::class, [
        
myClass::class, 
        
myTrait::class, 
        
myInterface::class
    ], [
    
"__construct" => function() {
        
/* ... */
    
}
]);

var_dump(
 
class_uses(Composed::class),
 
class_parents(Composed::class),
 
class_implements(Composed::class));
?>

以上例程会输出:

array(1) {
  ["myTrait"]=>
  string(7) "myTrait"
}
array(1) {
  ["myClass"]=>
  string(7) "myClass"
}
array(1) {
  ["myInterface"]=>
  string(11) "myInterface"
}
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.uopz-compose.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3