anything incorrect?

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

    anything incorrect?

    why i do not see anything but a blank page?

    <?php
    function somma($uno,$due )
    {
    $totale = $uno + $due;
    return($totale) ;
    }
    $sum = somma(3,4);
    $totale = $resto;
    print("$resto") ;
    print("$totale" );
    ?>

    please help me, i have a test!

  • Andy Hassall

    #2
    Re: anything incorrect?

    On 28 May 2007 11:05:05 -0700, vinnie <centro.gamma@g mail.comwrote:
    >why i do not see anything but a blank page?
    >
    ><?php
    >function somma($uno,$due )
    {
    $totale = $uno + $due;
    return($totale) ;
    }
    >$sum = somma(3,4);
    >$totale = $resto;
    >print("$resto" );
    >print("$totale ");
    >?>
    >
    >please help me, i have a test!
    You haven't got error_reporting turned up high enough. Set it to E_ALL to see
    the warnings your code produces.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Philipp Grassl

      #3
      Re: anything incorrect?

      <?php
      function somma($uno,$due )
      {
      $totale = $uno + $due;
      return($totale) ;
      }
      $sum = somma(3,4);
      print("$sum");
      ?>

      You mean like this?

      vinnie schrieb:
      why i do not see anything but a blank page?
      >
      <?php
      function somma($uno,$due )
      {
      $totale = $uno + $due;
      return($totale) ;
      }
      $sum = somma(3,4);
      $totale = $resto;
      print("$resto") ;
      print("$totale" );
      ?>
      >
      please help me, i have a test!
      >

      Comment

      • vinnie

        #4
        Re: anything incorrect?

        On May 28, 2:13 pm, Philipp Grassl <p.gra...@gmx.a twrote:
        <?php
        function somma($uno,$due )
        {
        $totale = $uno + $due;
        return($totale) ;}
        >
        $sum = somma(3,4);
        print("$sum");
        ?>
        >
        You mean like this?
        >
        vinnie schrieb:
        >
        why i do not see anything but a blank page?
        >
        <?php
        function somma($uno,$due )
        {
        $totale = $uno + $due;
        return($totale) ;
        }
        $sum = somma(3,4);
        $totale = $resto;
        print("$resto") ;
        print("$totale" );
        ?>
        >
        please help me, i have a test!
        exactly, thanks a lot!!!!

        Comment

        • farrishj@gmail.com

          #5
          Re: anything incorrect?

          On May 28, 1:05 pm, vinnie <centro.ga...@g mail.comwrote:
          why i do not see anything but a blank page?
          >
          <?php
          function somma($uno,$due )
          {
          $totale = $uno + $due;
          return($totale) ;
          }
          $sum = somma(3,4);
          $totale = $resto;
          print("$resto") ;
          print("$totale" );
          ?>
          First things first: use a code formatting style that is easier to
          read. Visit http://en.wikipedia.org/wiki/Prettyprint to learn more.

          <code>
          // I like C-style
          <h4>Test of somma function</h4>
          <p>
          <?php

          function somma($uno,$due ) {
          $totale = $uno + $due;
          return $totale;
          }

          $sum = somma(3,4);
          $totale = $sum; // Here, this was $resto, which is not pre-assigned a
          value
          print($resto); // Before, printed nothing, since $resto did not point
          to anything
          print($totale); // Before, a pointer to nothing ($resto)

          ?>
          </p>
          </code>

          The error may be a scoping issue, an error in naming a variable, or
          both. However, php is doing what is expected.

          Since $totale is in a function where it is assigned a value, it is
          considered "in the scope of the function" and is not available to the
          global-space variable declaration. To make it accessible, you have to
          import the global $variable:

          <code>
          function somma($uno,$due ) {
          global $totale;
          // continue code with $totale available
          }
          </code>

          You can also pass by reference:

          <code>
          function somma($uno, $due, &$totale) { // <-- Notice ampersand (&)
          $totale = $uno + $due;
          return($totale) ;
          }
          </code>

          But then, somewhat inexplicably, you assign $totale to a non-declared
          $sum variable (which will make $totale === null), and then try to
          print both.

          Note how I put a page title and a horizontal rule (<hr />) tag before
          and after the code I expect to output for testing. This tells me if
          the page died on parse (one kind of error, like not escaping a
          sequence correctly), if the page died on processing (like calling a
          function that doesn't exist), or if, in this case, the code has
          nothing to output. This helps troubleshoot the code more efficiently
          and effectively.

          Comment

          Working...