PHP.mk документација

Componere\Definition

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

class.componere-definition.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека class.componere-definition.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Componere\Definition

Референца за `class.componere-definition.php` со подобрена типографија и навигација.

class.componere-definition.php

Класата Componere\Definition

(Componere 2 >= 2.1.0)

Вовед

Класата Definition му овозможува на програмерот да гради и регистрира тип во време на извршување.

Ако една Definition замени постоечка класа, постоечката класа ќе биде вратена кога Definition ќе биде уништена.

Синопсис на класата

final class Componere\Definition extends Componere\Abstract\Definition {
/* Конструктори */
public __construct(string $name)
public __construct(string $name, string $parent)
public __construct(string $name, array $interfaces)
public __construct(string $name, string $parent, array $interfaces)
/* Методи */
public addConstant(string $name, Componere\Value $value): Уништено од
public addProperty(string $name, Componere\Value $value): Уништено од
public register(): void
public isRegistered(): bool
public getClosures(): array
/* Наследени методи */
public Componere\Abstract\Definition::addInterface(string $interface): Уништено од
public Componere\Abstract\Definition::addMethod(string $name, Componere\Method $method): Уништено од
public Componere\Abstract\Definition::addTrait(string $trait): Уништено од
}

Содржина

Белешки од корисници 1 белешка

Tr909 at com dot nospam dot bigfoot
пред 8 години
Sometimes we might wish to extend a third party class that has been defined as "final". 

In this example, the a child class will extend a "final" class, adding a method. An object instance will be able to access parent members, and is recognized as an instance of both the dynamically created child class as well as its parent class.

<?php
declare(strict_types=1);

/*
 *  Final class would normally prevent extending.
 */
final class ParentC
{
    public $parentvar;
    public $secondvar;
    
    function __construct() { echo( "\r\n<br/>".$this->parentvar = 'set by '.get_class().'->parentconstruct' ); }
    function parentf() { echo( "\r\n<br/>".get_class().'->parentf >> '.$this->parentvar ); }
}

/*
 *  Dynamically define a child class "DynamicC" 
 *  which successfully extends final class "ParentC".
 */
$DefC = new \Componere\Definition( 'DynamicC', 'ParentC');

// Extend child class with method 'DynamicC::dynamicf()'.
$DefM = new Componere\Method( function( $parm = null ) {
    // Populate a parent class property.
    $this->secondvar = empty( $parm ) ? 'set by '.get_class().'->dynamicf' : $parm;
    // Access an inherited property set by parent constructor.
    echo( "\r\n<br/>".get_class().'->dynamicf >> '.$this->parentvar ); 
} );
$DefC->addMethod( 'dynamicf', $DefM );

// Take dynamic child class 'life'.
$DefC->register();

/*
 *  Instantiate the dynamic child class,
 *  and access its own and inherited members.
 */

$dyno = new DynamicC;
$dyno->parentf();
$dyno->dynamicf( 'myvalue ');

// Our object is also recognized as instance of parent!
var_dump( $dyno instanceof DynamicC, $dyno instanceof ParentC );
var_dump( $dyno ); 
%>

will output:

set by ParentC->parentconstruct 
ParentC->parentf >> set by ParentC->parentconstruct 
DynamicC->dynamicf >> set by ParentC->parentconstruct

(boolean) true
(boolean) true

object(DynamicC)
  public 'parentvar' => string 'set by ParentC->parentconstruct' (length=31)
  public 'secondvar' => string 'myvalue ' (length=8)
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.