get_object_vars

(PHP 4, PHP 5, PHP 7, PHP 8)

get_object_varsRestituisce le proprietà dell'oggetto dato

Descrizione

get_object_vars(object $object): array

Restituisce le proprietà non-statiche accessibili dell'object dato in base all'ambito.

Elenco dei parametri

object

Un'istanza dell'oggetto.

Valori restituiti

Restituisce un array associativo delle proprietà non-statiche accessibili dell'oggetto definito per l'object specificato nell'ambito. Se ad una proprietà non è stato assegnato un valore, essa verrà restituita con un valore null.

Log delle modifiche

Versione Descrizione
5.3.0 Questa funzione ora restituisce null se object non è un oggetto. In precedenza veniva restituito false.

Esempi

Example #1 Uso di get_object_vars()

<?php

class foo {
private
$a;
public
$b = 1;
public
$c;
private
$d;
static
$e;

public function
test() {
var_dump(get_object_vars($this));
}
}

$test = new foo;
var_dump(get_object_vars($test));

$test->test();

?>

Il precedente esempio visualizzerà:

array(2) {
  ["b"]=>
  int(1)
  ["c"]=>
  NULL
}
array(4) {
  ["a"]=>
  NULL
  ["b"]=>
  int(1)
  ["c"]=>
  NULL
  ["d"]=>
  NULL
}

Vedere anche: