Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Cannot access public properties?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Cannot access public properties?

Postby avacacie » Mon Oct 29, 2012 1:32 am

Hi all,

This is my first post here. This forum looks interesting indeed :)

See, I'm trying to debug a PHP-written web application. So far I'm not coming across many difficulties... but then I hit this one.

There's this object (names "plazo") with several public properties. If you do var_dump($this->plazo), you get:

array
0 =>
object(Plazo)[20]
private 'plazo_tramitacion_pk' => null
private 'dias_plazo' => null
private 'dias_antelacion_aviso' => null
private 'estado_inicial_fk' => null
private 'estado_final_fk' => null
public 'PLAZO_TRAMITACION_PK' => string '11' (length=2)
public 'DIAS_PLAZO' => string '20' (length=2)
public 'DIAS_ANTELACION_AVISO' => string '2' (length=1)
public 'ESTADO_INICIAL_FK' => string '10' (length=2)
public 'ESTADO_FINAL_FK' => string '11' (length=2)
public 'ESTADO_PROCEDIMIENTO_PK' => string '11' (length=2)
public 'C_ESTADO_PROCEDIMIENTO' => string 'HCES' (length=4)
public 'ESTADO_INICIAL' => string 'Pendiente de Subsanación' (length=25)
public 'TIPO_PROCEDIMIENTO_FK' => string '2' (length=1)
public 'ESTADO_FINAL' => string 'Pendiente de Evaluar Solicitud' (length=30)
public 'TIPO_PROCEDIMIENTO_PK' => string '2' (length=1)
public 'C_TIPO_PROCEDIMIENTO' => string 'HC' (length=2)
public 'D_TIPO_PROCEDIMIENTO' => string 'Solicitud de Homologación de Contenidos' (length=40)

But then, if I want to echo one of the public properties (for example echo $this->plazo->D_TIPO_PROCEDIMIENTO), I get... nothing, null, nada. :?

I've tried several things, but I'm afraid it's been years since I last coded in PHP (actually, PHP5 wasn't even out when I worked as a PHP-coder on a daily basis!) so I'm a bit confused now.

Any clues?

Thanks a lot in advance! :)
avacacie
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Oct 29, 2012 1:25 am

Re: Cannot access public properties?

Postby MeroD » Mon Oct 29, 2012 11:03 pm

Code: Select all
class MyClass
{
    public $public = 'Public';
    protected $protected = 'Protected';
    private $private = 'Private';

    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}

$obj = new MyClass();
echo $obj->public; // Works
echo $obj->protected; // Fatal Error
echo $obj->private; // Fatal Error
$obj->printHello(); // Shows Public, Protected and Private


http://www.php.net/manual/en/language.o ... bility.php
MeroD
New php-forum User
New php-forum User
 
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: Cannot access public properties?

Postby avacacie » Mon Oct 29, 2012 11:21 pm

Hi MeroD,

Thanks but, AFAIK the properties I'm trying to access are public.
For example:

public 'D_TIPO_PROCEDIMIENTO' => string 'Solicitud de Homologación de Contenidos' (length=40)

Note also that I don't get any errors when trying to echo that property - simply the echo function doesn't return anything.

This is what puzzles me most - the properties are public, hence visible, but when accessed return an empty value. If I do: var_dump($this->plazos->D_TIPO_PROCEDIMIENTO) I only get "null".

Any more ideas?
avacacie
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Oct 29, 2012 1:25 am

Re: Cannot access public properties?

Postby MeroD » Wed Oct 31, 2012 10:50 pm

Nope, sorry...

Maybe one of the other OO experts on here can help. Maybe try asking this question on Stackoverflow?
MeroD
New php-forum User
New php-forum User
 
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: Cannot access public properties?

Postby avacacie » Fri Nov 02, 2012 3:17 am

Thanks again,

I will go on with my "research" :)
avacacie
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon Oct 29, 2012 1:25 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron