PHP 8.5.0 Alpha 2 available for testing

ReflectionGenerator::getThis

(PHP 7, PHP 8)

ReflectionGenerator::getThisObtiene el valor de $this del generador

Descripción

public ReflectionGenerator::getThis(): ?object

Obtiene el valor de $this del generador al que tiene acceso.

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

Devuelve el valor de $this, o null si el generador no ha sido creado en un contexto de clase.

Ejemplos

Ejemplo #1 Ejemplo con ReflectionGenerator::getThis()

<?php

class GenExample
{
public function
gen()
{
yield
1;
}
}

$gen = (new GenExample)->gen();

$reflectionGen = new ReflectionGenerator($gen);

var_dump($reflectionGen->getThis());

Resultado del ejemplo anterior es similar a :

object(GenExample)#3 (0) {
}

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top