access descendant properties of mySQLi in php

2

Dear   I have extended the class mysqli in php but when doing print_r the public properties that I have added to the class are not shown:

here is an example:

<?php
  // define una nueva clase 
class miClase extends mysqli{

public $miPropiedad;
public $miOtraPropiedad;

public function __construct ( $host='localhost',$username='user',$passwd='1234',$dbname='base' ){
    $this->miPropiedad = 'Hola';
    parent::__construct ( $host,$username,$passwd,$dbname );
    $this->miOtraPropiedad = 'Chao';
}
}// class

$miObjeto = new miClase();
echo $miObjeto->miPropiedad ,"\n";     // las nuevas propiedades son accesible
echo $miObjeto->miOtraPropiedad ,"\n";

print_r( $miObjeto );  // no muestra las nuevas propiedades

The output of this is:

Hola
Chao
miClase Object
(
    [affected_rows] =>
    [client_info] =>
    [client_version] => 50011
    [connect_errno] => 1045
    [connect_error] => Access denied for user 'user'@'localhost' (using password: YES)
    [errno] =>
    [error] =>
    [error_list] =>
    [field_count] =>
    [host_info] =>
    [info] =>
    [insert_id] =>
    [server_info] =>
    [server_version] =>
    [stat] =>
    [sqlstate] =>
    [protocol_version] =>
    [thread_id] =>
    [warning_count] =>
)

I've tried rewriting __debugInfo() but it's never called: (

Any ideas on how to make the added properties visible?

Thank you very much

    
asked by Juan Manuel Doren 21.05.2016 в 11:02
source

1 answer

1

Try using " Reflection "

$class = new ReflectionClass('miClase');
$props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
var_dump($props);

More info here: link

    
answered by 12.10.2016 в 00:25