anything incorrect?

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($...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-28-2007
vinnie
 
Posts: n/a
Default 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!

Reply With Quote
  #2 (permalink)  
Old 05-28-2007
Andy Hassall
 
Posts: n/a
Default Re: anything incorrect?

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
Reply With Quote
  #3 (permalink)  
Old 05-28-2007
Philipp Grassl
 
Posts: n/a
Default 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!
>

Reply With Quote
  #4 (permalink)  
Old 05-28-2007
vinnie
 
Posts: n/a
Default Re: anything incorrect?

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!!!!

Reply With Quote
  #5 (permalink)  
Old 05-28-2007
farrishj@gmail.com
 
Posts: n/a
Default Re: anything incorrect?

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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0