global variables, Apache, PHP4.4.1Win32, WinXP

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

    global variables, Apache, PHP4.4.1Win32, WinXP

    How do I get a function to see a global variable without employing
    a parameter list?

    The source code:

    <html><head>
    <title>Simple Global Variable / Function Test</title>
    <?php
    $counter_file = "counter.tx t"; // global variable

    //quickquote function
    function qq($sQuoteMe, $sQuoteChar) {
    return("$sQuote Char$sQuoteMe$s QuoteChar");
    }

    function updatecount() {
    echo('<p>$count er_file = ' . "$counter_f ile</p>\n");
    }
    ?>
    </head>
    <body><?php
    echo('<p>$count er_file = ' . qq($counter_fil e, "&quot;") . "</p>\n");
    // echo('Hits: ' . qq("qq test", '&quot;'));
    echo('<p>Hits: ' . qq(updatecount( ), "&quot;") . "</p>\n");
    ?></body></html>

    ... echos the following HTML to the browser ...

    <html><head>
    <title>Simple Global Variable / Function Test</title>
    </head>
    <body><p>$count er_file = &quot;counter.t xt&quot;</p>
    <p>Hits: &quot;&quot; </p>
    </body></html>

    Thanks.

    Jim Carlock
    Post replies to the newsgroup.

    P.S. (For the people at php.net)...
    The Zend Optimizer link on this page results in a 404 page. Search for
    "Zend Optimizer" on the following page:
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.



  • Jim Carlock

    #2
    Re: global variables, Apache, PHP4.4.1Win32, WinXP

    I put my vote in for the

    Option Explicit '(.asp/vbscript) (use strict //perl)

    as a requested improvement.



    Only 17 votes there right at the moment. If anyone else would like
    such an improvement, go to the link above and vote.

    Jim Carlock
    Post replies to the newsgroup.


    Comment

    • Al

      #3
      Re: global variables, Apache, PHP4.4.1Win32, WinXP


      Jim Carlock wrote:[color=blue]
      > I put my vote in for the
      >
      > Option Explicit '(.asp/vbscript) (use strict //perl)
      >
      > as a requested improvement.
      >
      > http://bugs.php.net/bug.php?id=14285&thanks=6
      >
      > Only 17 votes there right at the moment. If anyone else would like
      > such an improvement, go to the link above and vote.
      >
      > Jim Carlock
      > Post replies to the newsgroup.[/color]

      Well if you set your error level thingy to E_ALL it'll throw a notice
      if you use a variable that you haven't instantiated. But instantiation
      basically means 'setting'. So you can do this code:

      <?php

      $counter = 3;

      $countr = $counter + 1; // notice the error (and i only didn't use
      $countr++ because that might actually throw the notice)

      echo $counter;

      ?>

      and it won't throw a notice as you're using the NEW $countr variable in
      a setting sense. However it does help you a little with regards to
      CHECKING a variable, e.g.:

      <?php

      $counter = 3;

      echo $countr;

      ?>

      that should throw a notice with errors at E_ALL.

      But that's nowhere near a nice Option Explicit.

      Comment

      • Al

        #4
        Re: global variables, Apache, PHP4.4.1Win32, WinXP

        Al wrote:[color=blue]
        > Well if you set your error level thingy to E_ALL it'll throw a notice
        > if you use a variable that you haven't instantiated. But instantiation
        > basically means 'setting'.[/color]

        Heh just read that page you linked to and it's totally explained there.
        Probably better than I did too.

        Comment

        Working...