Var in PHP 5 question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pfrank26@hotmail.com

    #1

    Var in PHP 5 question

    Hi all,
    I've written a large system for PHP4 that declares class variables
    using the 'var' keyword. I'm now upgrading to PHP5, and it seems I have
    to change 'var' to private / public / protected, which don't work in
    PHP4. Is there anyway to make my system compatible with both versions?

    Cheers,
    Paul.

  • Janwillem Borleffs

    #2
    Re: Var in PHP 5 question

    pfrank26@hotmai l.com wrote:[color=blue]
    > I've written a large system for PHP4 that declares class variables
    > using the 'var' keyword. I'm now upgrading to PHP5, and it seems I
    > have to change 'var' to private / public / protected, which don't
    > work in PHP4. Is there anyway to make my system compatible with both
    > versions?
    >[/color]

    The var keyword is supported in PHP5, albeit deprecated. If you want your
    code to be both backwards compatible and take advantage of PHP5's
    declaration style, the best thing you can do is to write classes for both
    versions and apply them conditionally:

    if (PHP_VERSION < 5) {
    include "php4class.php" ;
    } else {
    include "php5class.php" ;
    }

    $obj = new MyClass;


    JW



    Comment

    • Tony Marston

      #3
      Re: Var in PHP 5 question

      In PHP 5 this is reported as a warning, not an error, so it will still run
      OK. I know because I have encountered the same situation with code that I
      use which needs to run under both PHP 4 and PHP 5.

      --
      Tony Marston

      This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




      <pfrank26@hotma il.com> wrote in message
      news:1122210124 .890096.86560@g 44g2000cwa.goog legroups.com...[color=blue]
      > Hi all,
      > I've written a large system for PHP4 that declares class variables
      > using the 'var' keyword. I'm now upgrading to PHP5, and it seems I have
      > to change 'var' to private / public / protected, which don't work in
      > PHP4. Is there anyway to make my system compatible with both versions?
      >
      > Cheers,
      > Paul.
      >[/color]


      Comment

      Working...