get_object_vars() e get_class_vars()

16 views
Skip to first unread message

Tiago Farias

unread,
Sep 18, 2011, 9:05:15 PM9/18/11
to PHPRS
Ae pessoal, boa noite.

Como listar todos os atributos de uma classe, e seus valores onde
estes tem a visibilidade privada.
Tentei usar a função "get_object_vars()" e "get_class_vars()" mas só
consegui fazer retornar se mudar a vilibilidade para public.
Alguma idéida de como resolver isso?

Marcelo Rezende

unread,
Sep 18, 2011, 10:18:41 PM9/18/11
to lista...@googlegroups.com
Acredito que isso possa ser feito através de um override no método __toString


Marcelo Rezende
mal...@gmail.com
@iPad

> --
> You received this message because you are subscribed to the Google
> Groups "PHPRS" group.
> To post to this group, send email to lista...@googlegroups.com
> To unsubscribe from this group, send email to
> lista-phprs...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/lista-phprs?hl=en

Anderson A. Meggiolaro

unread,
Sep 18, 2011, 10:26:25 PM9/18/11
to lista...@googlegroups.com

http://php.net/manual/en/class.reflectionclass.php




2011/9/18 Tiago Farias <tiago.fa...@gmail.com>
--
You received this message because you are subscribed to the Google
Groups "PHPRS" group.
To post to this group, send email to lista...@googlegroups.com
To unsubscribe from this group, send email to
lista-phprs...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/lista-phprs?hl=en



--

------------------------------------------------
Anderson A. Meggiolaro
Analista Programador de TI
------------------------------------------------

Marcel Araujo

unread,
Sep 18, 2011, 10:40:29 PM9/18/11
to lista...@googlegroups.com
Use Reflection!

--
You received this message because you are subscribed to the Google
Groups "PHPRS" group.
To post to this group, send email to lista...@googlegroups.com
To unsubscribe from this group, send email to
lista-phprs...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/lista-phprs?hl=en



--

Marcel Araujo
Analista de Sistemas
Administrador CodeIgniter.com.br
Desenvolvedor PHP/CodeIgniter/Zend/JavaScript/ExtJS/jQuery
Linux User #490101

http://www.twitter.com/marcelaraujo
http://www.marcelaraujo.com.br
http://br.linkedin.com/in/marcelaraujo


Tiago O. de Farias

unread,
Sep 19, 2011, 11:07:18 AM9/19/11
to lista...@googlegroups.com
Ae pessoal, dei uma olhada em 'reflection' mas achei meio complicado. Mas resolvi assim:

public static function getValCol($objeto)
    {
        $n = strlen(get_class($objeto));
       
        $arrObjeto = (array) $objeto;

        foreach ($arrObjeto as $indice => $var) {
            $array[substr($indice, $n+1)] = $var;
        }
        self::$colunas = implode(" , ", array_keys($array));
        self::$valores = implode(" , ", array_values($array));
--
Att, Tiago O. de Farias
Reply all
Reply to author
Forward
0 new messages