Basic PHP4 Class question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aggelos

    Basic PHP4 Class question

    Hello,
    if i have the folowing class:

    class person {
    var $name;
    var $surname;
    var $flag;
    function person($name=NU LL,$surname=NUL L) {
    $this->name = $name;
    $this->surname = $surname;
    $this->flag = 1;
    }
    function displayPerson($ person) {
    print_r($person );
    }
    }

    I can do the folowing without instantiating the class :
    $person = new person('Fred',' Jones');
    person::display Person($person) ;

    is there anyway to access the $flag variable in the contructor without
    having to do $person = new person() ?

    Something like echo person::$flag; ? <------- I know that this is not
    right. I am just asking if there is something simmilar tha I can do.

    Thank you,
    Angelos.
    Is there anyway

  • Andy Hassall

    #2
    Re: Basic PHP4 Class question

    On 20 Dec 2006 08:25:58 -0800, "Aggelos" <djjelly@gmail. comwrote:
    >if i have the folowing class:
    >
    >class person {
    var $name;
    var $surname;
    var $flag;
    function person($name=NU LL,$surname=NUL L) {
    $this->name = $name;
    $this->surname = $surname;
    $this->flag = 1;
    }
    function displayPerson($ person) {
    print_r($person );
    }
    >}
    >
    >I can do the folowing without instantiating the class :
    >$person = new person('Fred',' Jones');
    >person::displa yPerson($person );
    >
    >is there anyway to access the $flag variable in the contructor without
    >having to do $person = new person() ?
    >
    >Something like echo person::$flag; ? <------- I know that this is not
    >right. I am just asking if there is something simmilar tha I can do.
    I don't quite understand what you're asking; the closest might be static
    properties?



    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Aggelos

      #3
      Re: Basic PHP4 Class question

      I don't quite understand what you're asking; the closest might be static
      properties?
      Thats exactly what I need but I am developing in PHP4 not 5 :S

      Thank you.

      Comment

      • Janwillem Borleffs

        #4
        Re: Basic PHP4 Class question

        Aggelos wrote:
        > I don't quite understand what you're asking; the closest might be
        >static properties?
        Thats exactly what I need but I am developing in PHP4 not 5 :S
        >
        With PHP 4, your only bet would be get_class_vars( ):



        E.g.:

        class Foo { var $static = 1; }
        $vars = get_class_vars( 'Foo');

        print $vars['static'];


        JW


        Comment

        • Aggelos

          #5
          Re: Basic PHP4 Class question

          With PHP 4, your only bet would be get_class_vars( ):
          >

          >
          E.g.:
          >
          class Foo { var $static = 1; }
          $vars = get_class_vars( 'Foo');
          >
          print $vars['static'];
          Oh thanks a lot for that. DIdn't know it.

          Comment

          Working...