You are here: Re: why this error? « PHP Programming Language « IT news, forums, messages
Re: why this error?

Posted by purcaholic on 05/28/07 21:52

On 28 Mai, 23:36, vinnie <centro.ga...@gmail.com> wrote:
> This is my first "class" algorithm: when i execute it, i get this
> error:
>
> <<Fatal error: Call to undefined function: sum() in d:\class.php on
> line 20>>
>
> what's wrong? The class has the function, so why it says undefined?
>
> <?php
> print("first time class");
> class somma
> {
> var $uno=10;
> var $due=15;
> var $tre=15;
> function sum($uno, $due, $tre)
> {
> $totale = $uno + $due + $tre;
> return($totale);
> }
> function sum_2()
> {
> $totale = $this->sum($this->uno, $this->due, $this->tre);
> return $totale;
> }
> }
> $sum=sum(34,40);
> print("$sum");
> ?>

Hi vinnie,

you have declared sum function inside the somma class, and you're
trying to use it outside the class scope. This will not work.

First you should create an instance of somma and then call the sum
function using "->" operator.
Example:
[snip]
$mySomma = new somma();
$sum=$mySomma->sum(34,40);
print("$sum");
[/snap]

purcaholic

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация