Bug with array declaration in class

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

    Bug with array declaration in class

    Hi,

    Can someone confirm this problem:

    This works:

    var $x = array(
    "x" => "x".
    "y",
    "y" => "a".
    "b"
    );
    }

    var_dump($x);


    But this doesn't work:

    class g{
    var $x = array(
    "x" => "x".
    "y",
    "y" => "a".
    "b"
    );
    }

    $g = new g();

    var_dump($g->x);

    It throws

    Parse error: parse error, expecting `')'' in x.php on line 5


    I know I have an outdated version of PHP (4.3.2), but it is compiled
    with a special MSSQl extension and I cannot seem to compile the patch
    with 4.3.3 and 4.3.4. The patch reads the milliseconds for dates.
    There's a workaround, but it would involve heaps of testing again.

    Just wanted to see, if its worth going to a different version.

    Jochen




    --
    Jochen Daum - Cabletalk Group Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

  • Garp

    #2
    Re: Bug with array declaration in class


    "Jochen Daum" <jochen.daum@ca bletalk.co.nz> wrote in message
    news:a24pf0db0t qhe42tsmhi1uscb nitkc82qq@4ax.c om...[color=blue]
    > Hi,
    >
    > Can someone confirm this problem:[/color]
    <snip initialisation in declaration>

    As a workaround, initialise it in the constructor.

    class g{
    var $x;

    function g() {
    $this->x = array(
    "x" => "x".
    "y",
    "y" => "a".
    "b"
    );
    }
    }

    Garp


    Comment

    • Jochen Daum

      #3
      Re: Bug with array declaration in class

      Hi Garp,

      On Tue, 20 Jul 2004 05:14:47 GMT, "Garp" <i_am@home.no w> wrote:
      [color=blue]
      >
      >"Jochen Daum" <jochen.daum@ca bletalk.co.nz> wrote in message
      >news:a24pf0db0 tqhe42tsmhi1usc bnitkc82qq@4ax. com...[color=green]
      >> Hi,
      >>
      >> Can someone confirm this problem:[/color]
      ><snip initialisation in declaration>
      >
      >As a workaround, initialise it in the constructor.
      >[/color]

      Cheers, so you have the same problem on which PHP version?

      Jochen
      --
      Jochen Daum - Cabletalk Group Ltd.
      PHP DB Edit Toolkit -- PHP scripts for building
      database editing interfaces.
      Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

      Comment

      • Zurab Davitiani

        #4
        Re: Bug with array declaration in class

        Jochen Daum wrote:
        [color=blue]
        > Cheers, so you have the same problem on which PHP version?[/color]

        This is not really a "problem" with PHP4, but just how it was designed.
        Please read:

        PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


        especially these examples:

        <?php
        class Cart {
        /* None of these will work in PHP 4. */
        var $todays_date = date("Y-m-d");
        var $name = $firstname;
        var $owner = 'Fred ' . 'Jones';
        /* Arrays containing constant values will, though. */
        var $items = array("VCR", "TV");
        }

        /* This is how it should be done. */
        class Cart {
        var $todays_date;
        var $name;
        var $owner;
        var $items = array("VCR", "TV");

        function Cart() {
        $this->todays_date = date("Y-m-d");
        $this->name = $GLOBALS['firstname'];
        /* etc. . . */
        }
        }
        ?>

        Just like Garp suggested.

        Comment

        • Jochen Daum

          #5
          Re: Bug with array declaration in class

          Hi,

          On Tue, 20 Jul 2004 05:24:50 GMT, Zurab Davitiani <agt@mindless.c om>
          wrote:
          [color=blue]
          >Jochen Daum wrote:
          >[color=green]
          >> Cheers, so you have the same problem on which PHP version?[/color]
          >
          >This is not really a "problem" with PHP4, but just how it was designed.
          >Please read:
          >
          >http://www.php.net/manual/en/language.oop.php
          >[/color]
          Right. Good Point.


          Jochen
          --
          Jochen Daum - Cabletalk Group Ltd.
          PHP DB Edit Toolkit -- PHP scripts for building
          database editing interfaces.
          Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

          Comment

          • Garp

            #6
            Re: Bug with array declaration in class


            "Jochen Daum" <jochen.daum@ca bletalk.co.nz> wrote in message
            news:m7bpf0p8k6 d9n02b3hv8df7eb a39ktd3am@4ax.c om...[color=blue]
            > Hi,
            >
            > On Tue, 20 Jul 2004 05:24:50 GMT, Zurab Davitiani <agt@mindless.c om>
            > wrote:
            >[color=green]
            > >Jochen Daum wrote:
            > >[color=darkred]
            > >> Cheers, so you have the same problem on which PHP version?[/color]
            > >
            > >This is not really a "problem" with PHP4, but just how it was designed.
            > >Please read:
            > >
            > >http://www.php.net/manual/en/language.oop.php
            > >[/color]
            > Right. Good Point.[/color]

            Yeah, what Zurab said. Hope you solved your problem anyway.

            Garp


            Comment

            Working...