difference between var and private in a class

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

    difference between var and private in a class

    I've looked everywhere (including php.net) and can't seem to find the answer
    to this simple question.

    What's the difference between var and private when initializing a variable
    in a class?

    For example:

    class myClass {

    var $var1;
    private $var2;

    // constructor
    function myClass() {
    // do something
    }

    }


  • Michael Fesser

    #2
    Re: difference between var and private in a class

    ..oO(Bosconian)
    >I've looked everywhere (including php.net) and can't seem to find the answer
    >to this simple question.
    >
    >What's the difference between var and private when initializing a variable
    >in a class?
    'var' is deprecated and should be replaced with 'public'. From the
    manual:

    | Note: The PHP 4 method of declaring a variable with the var keyword is
    | still supported for compatibility reasons (as a synonym for the public
    | keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT
    | warning.

    Visibility


    Micha

    Comment

    • palle

      #3
      Re: difference between var and private in a class

      Bosconian wrote:
      I've looked everywhere (including php.net) and can't seem to find the answer
      to this simple question.
      >
      What's the difference between var and private when initializing a variable
      in a class?
      >
      For example:
      >
      class myClass {
      >
      var $var1;
      private $var2;
      >

      var is used in PHP4
      it is still supported in PHP5, and is equal to public

      Comment

      • Bosconian

        #4
        Re: difference between var and private in a class

        "Michael Fesser" <netizen@gmx.de wrote in message
        news:kmsbr2tt7d o79uaffb14t5t2g 7s6r2so1s@4ax.c om...
        .oO(Bosconian)
        >
        >>I've looked everywhere (including php.net) and can't seem to find the
        >>answer
        >>to this simple question.
        >>
        >>What's the difference between var and private when initializing a variable
        >>in a class?
        >
        'var' is deprecated and should be replaced with 'public'. From the
        manual:
        >
        | Note: The PHP 4 method of declaring a variable with the var keyword is
        | still supported for compatibility reasons (as a synonym for the public
        | keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT
        | warning.
        >
        Visibility

        >
        Micha
        Ah-ha, very good. Thanks so much.


        Comment

        Working...