This is a discussion on anything incorrect? within the PHP Language forums, part of the PHP Programming Forums category; why i do not see anything but a blank page? <?php function somma($uno,$due) { $totale = $uno + $due; return($...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On 28 May 2007 11:05:05 -0700, vinnie <centro.gamma@gmail.com> wrote:
>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.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool |
|
|||
|
<?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! > |
|
|||
|
On May 28, 2:13 pm, Philipp Grassl <p.gra...@gmx.at> wrote:
> <?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!!!! |
|
|||
|
On May 28, 1:05 pm, vinnie <centro.ga...@gmail.com> wrote:
> 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. |