Results 1 to 9 of 9

Thread: PHP 4: static

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved PHP 4: static

    I don't know if PHP 4 supports static but I need help on achieving this or workaround on having something like
    Code:
    <?php
    class test {
      static $a;
      
      function b() {
        if (!isset(test::$a)) {
          test::$a = "hello world";
        }
        return test::$a;
      }
    }
    
    echo test::b();
    Thanks.
    Last edited by nebulom; May 22nd, 2007 at 09:20 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP 4: static

    Static is supported in PHP4. Access static variables using the scope resolution operator:
    PHP Code:
    test::$a 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: PHP 4: static

    I've got PHP Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in C:\Program Files\Apache Group\Apache2\htdocs\tests\_debug_tmp.php on line 6 with
    Code:
    <?php
    class test {
      var $a;
      
      function b() {
        if (!isset(test::$a)) {
          test::$a = "hello world";
        }
        return test::$a;
      }
    }
    
    echo test::b();
    ?>

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP 4: static

    I haven't quite worked out why you get a parse error but you replaced 'static' with 'var' which means you can no longer access $a statically.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: PHP 4: static

    static $a; has PHP Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in C:\Program Files\Apache Group\Apache2\htdocs\tests\_debug_tmp.php on line 3 I think there's no reserved keyword (for modifier) static for PHP 4. This is PHP 4 btw, pen. Thanks.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP 4: static

    Sorry, I don't have PHP 4 handy and so posted under the assumption that visualAd was correct. I'll remember not to do that in future.

    There is a solution in the manual for simulating static fields in PHP 4.
    http://au3.php.net/manual/en/keyword...ayim.php#58724

    Hope that helps.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: PHP 4: static

    Thanks, will look at it.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP 4: static

    I seem to remember using static variables in PHP.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: PHP 4: static

    But only in functions .... Sorry
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width