7 Replies - 791 Views - Last Post: 15 September 2012 - 10:51 AM Rate Topic: -----

#1 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Call to undefined function

Posted 14 September 2012 - 09:41 AM

I'm creating a small PHP script to calculate taxes in my country and have been getting this error: Fatal error: Call to undefined function reiknaLifeyrisFramlagVinnuveitanda() in C:\apache\htdocs\Aefingaverkefni01\skattautreikningar.php on line 134

The function in question is the following one:

function reiknaLifeyrisFramlagVinnuveitanda($laun)
	{
		$this->lifeyrissFramlagVinnuveitanda = $laun * 0.06; //Finnur 6% framlag vinnuveitanda til lfeyrissjs
		echo "ar sem launin eru $laun tti framlag vinnuveitanda til lfeyrissjs a vera: $this->lifeyrissFramlagVinnuveitanda <br />";
	}



This function is written or perhaps I should say defined well above the function I call it from.

I call it on line 18 in the following snippet:

function reiknaLaun($laun) // a reikna t tekjuskatt og lfeyrissj
	{
		if ($laun <= 230000)
		{
			$tekjuskattur = 0.3734; //37,43% er teki af launum undir 230 sund
		}
		
		else if ($laun > 230000 && $laun <= 704367)
		{
			$tekjuskattur = 0.4024; //40,24% er teki af launum  milli 230001 og 704367
		}
		
		else
		{
			$tekjuskattur = 0.4624; //46,24% er teki af launum yfir 704367
		}
		
		reiknaLifeyrisFramlagVinnuveitanda($laun); //Reikna t lfeyrisframlag vinnuveitanda og set a  private breytu
		reiknaLifeyrisFramlagLaunthega($laun); //Reikna t lfeyrisframlag launega og set a  private breytu
		$laun += $this->lifeyrissFramlagVinnuveitanda; // (San arf a leggja 6% ofan  launin (framlag vinnuveitanda))
		
		//reikna tekjuskatt af allri upphinni
		$laun -= reiknaTekjuSkattMedTillitiTilPersonuafslatts($tekjuskattur, $laun);
		
		//og svo a draga lfeyrissjinn aftur fr v sem eftir stendur (10% samanlagt).
		
		reiknaHeildarLifEyrisFramlag(); 
		$laun -= $this->heildarLifeyrisFramlag; 
		
		return $laun; 
	}



And perhaps it's worth mentioning how I call the class in this file from another file:

require_once 'skattautreikningar.php'; 

$skattur1 = new Skattur(); 

$skattur1->reiknaLaun("200000");



Anyone have any idea what I'm doing wrong? Everything's written correctly as far as I can tell.

Is This A Good Question/Topic? 0
  • +

Replies To: Call to undefined function

#2 StefanOnRails  Icon User is offline

  • D.I.C Head

Reputation: 35
  • View blog
  • Posts: 106
  • Joined: 31-July 12

Re: Call to undefined function

Posted 14 September 2012 - 10:43 AM

Well, in PHP in order to call a method (function) you use $this->function_name(); (if the function is called inside the class)
Was This Post Helpful? 3
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,547
  • Joined: 23-August 08

Re: Call to undefined function

Posted 14 September 2012 - 11:00 AM

Damn, I thought *I* used long names :)
Was This Post Helpful? 1
  • +
  • -

#4 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Call to undefined function

Posted 14 September 2012 - 11:47 AM

View PostStefanOnRails, on 14 September 2012 - 10:43 AM, said:

Well, in PHP in order to call a method (function) you use $this->function_name(); (if the function is called inside the class)


Thanks, problem solved. :detective:

View PostJackOfAllTrades, on 14 September 2012 - 11:00 AM, said:

Damn, I thought *I* used long names :)


Haha, yeah.. I'm aware of my tendency to use fairly long names. It's just, I try to make the name speak for the function. And sometimes no two words that can do that come to mind. Or three. Or four.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,547
  • Joined: 23-August 08

Re: Call to undefined function

Posted 14 September 2012 - 12:48 PM

Better to have descriptive names (within reason). I was chalking it up to the language, actually :)
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Call to undefined function

Posted 14 September 2012 - 03:19 PM

Icelandic is a lot of things, but succinct it is not :)

Out of curiosity, do your teachers want you to write it like that? I always wrote my code in English and never got any complaints.
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,547
  • Joined: 23-August 08

Re: Call to undefined function

Posted 14 September 2012 - 03:22 PM

I thought it might be your native language, Atli. Knew it was some variation of a Scandianavian language.
Was This Post Helpful? 0
  • +
  • -

#8 Tenderfoot  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 160
  • Joined: 21-March 12

Re: Call to undefined function

Posted 15 September 2012 - 10:51 AM

View PostAtli, on 14 September 2012 - 03:19 PM, said:

Icelandic is a lot of things, but succinct it is not :)

Out of curiosity, do your teachers want you to write it like that? I always wrote my code in English and never got any complaints.


They don't make it a requirement. However, the instructions for the assignment are in Icelandic, and the functions he asked for were written in Icelandic as well, so he basically gave us the names for those. So I write it like this for the teacher. The majority of the teachers write their code in Icelandic, and translate a fair bit of the terms used in programming. I wonder if you went to the same school as I - most likely did if you studied PHP. But I'm given to understand that the subjects have changed a fair bit so who knows.

Always wondered if you were Icelandic by the way - seen your name around in the erm.. reputation-hiscore-box more than a few times.

This post has been edited by Tenderfoot: 15 September 2012 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1