By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,189 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,189 IT Pros & Developers. It's quick & easy.

anything incorrect?

P: n/a
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!

May 28 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 28 May 2007 11:05:05 -0700, vinnie <ce**********@gmail.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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
May 28 '07 #2

P: n/a
<?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!
May 28 '07 #3

P: n/a
On May 28, 2:13 pm, Philipp Grassl <p.gra...@gmx.atwrote:
<?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!!!!

May 28 '07 #4

P: n/a
On May 28, 1:05 pm, vinnie <centro.ga...@gmail.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.

May 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.