Jump to content

php undef function

Go to solution Solved by dragosudeki,

I don't know PHP, but aren't you supposed to do it like this?

object->function()

Its a function of an object, like getNaam(). The error is occuring because it assumes you made a printGegevens() function, but you haven't. The printGegevens() is supplied under an object, but you are not using the correct syntax to use that function.

I am having some trouble with PHP I can't find out why it wont work.. 

 

I have the following error: 

Fatal error: Call to undefined function printGegevens() in C:\xampp\htdocs\OOP\persoon.php on line 29

this is persoon.php: 

<?php include_once("persoon.class.php"); ?><!DOCTYPE html><html lang="nl">	<head>		<title>OOP in PHP</title>		<meta name="author" content="Robin Bosman">	</head>	<body>	<?php		$jan = new persoon("Jan", 18, "man");		$truus = new persoon("Truus", 20, "vrouw");		echo '<br />De leeftijd van ' . $truus->getNaam() . ' is: ' . $truus->getLeeftijd();		$truus->setLeeftijd(22);		echo '<br />De leeftijd van ' . $truus->getNaam() . ' is: ' . $truus->getLeeftijd();		$renee = new Persoon("Renee", 21, "man");		$renee->setGeslacht("vrouw");		echo '<br />Het geslacht van ' . $renee->getNaam() . ' is: ' . $renee->getGeslacht();		$thara = new Persoon("Thara", 19, "vrouw");		$thara->setLeeftijd(20);		echo '<br />De leeftijd van ' . $jan->getNaam() . ' is ' . $jan->getLeeftijd();				echo '<br />De leeftijd van ' . $thara->getNaam() . ' is ' . $thara->getLeeftijd();		printGegevens($thara);		printGegevens($jan);		unset($jan);	?>	</body></html>

this is : persoon.class.php: 

<?phpclass Persoon{	private $_naam;	private $_leeftijd;	private $_geslacht;	function __construct($persoonsnaam, $leeftijd, $geslacht){		$this->_naam = $persoonsnaam;		$this->_leeftijd = $leeftijd;		$this->_geslacht = $geslacht;		echo '<br /> Nieuw Persoon object ' . $persoonsnaam . ' wordt aangemaakt.';	}	function setNaam($persoonsnaam){		if(is_string($persoonsnaam)){			$this->_naam = $persoonsnaam;		}		else{			echo '<br />Datatype error in setNaam() method';		}	}	function getNaam(){		return $this->_naam;	}	function setLeeftijd($leeftijd){		if(is_integer($leeftijd)){			$this->_leeftijd = $leeftijd;		}		else{			echo '<br /> Datatype error in setLeeftijd()';		}	}	function getLeeftijd(){		return $this->_leeftijd;	}	function setGeslacht($geslacht){		$this->_geslacht = $geslacht;	}	function getGeslacht(){		return $this->_geslacht;	}		public function printGegevens(){		$gegevens = '<br />de gegevens van ' . $this->_naam . ' zijn: </br>Leeftijd: ' . $this->_leeftijd . '<br />Geslacht: ' . $this->_geslacht;		echo $gegevens;	}	function __destruct(){		echo '<br />Persoon object ' . $this->_naam . ' wordt verwijderd';	}	}?>

Thanks for helping me out :) 

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
https://linustechtips.com/topic/348100-php-undef-function/
Share on other sites

Link to post
Share on other sites

off topic - i read that title as pulp fiction, i'll go away now.

 

Spoiler
Spoiler

AMD 5000 Series Ryzen 7 5800X| MSI MAG X570 Tomahawk WiFi | G.SKILL Trident Z RGB 32GB (2 * 16GB) DDR4 3200MHz CL16-18-18-38 | Asus GeForce GTX 3080Ti STRIX | SAMSUNG 980 PRO 500GB PCIe NVMe Gen4 SSD M.2 + Samsung 970 EVO Plus 1TB PCIe NVMe M.2 (2280) Gen3 | Cooler Master V850 Gold V2 Modular | Corsair iCUE H115i RGB Pro XT | Cooler Master Box MB511 | ASUS TUF Gaming VG259Q Gaming Monitor 144Hz, 1ms, IPS, G-Sync | Logitech G 304 Lightspeed | Logitech G213 Gaming Keyboard |

PCPartPicker 

Link to comment
https://linustechtips.com/topic/348100-php-undef-function/#findComment-4738519
Share on other sites

Link to post
Share on other sites

I don't know PHP, but aren't you supposed to do it like this?

object->function()

Its a function of an object, like getNaam(). The error is occuring because it assumes you made a printGegevens() function, but you haven't. The printGegevens() is supplied under an object, but you are not using the correct syntax to use that function.

Link to comment
https://linustechtips.com/topic/348100-php-undef-function/#findComment-4738547
Share on other sites

Link to post
Share on other sites

I don't know PHP, but aren't you supposed to do it like this?

object->function()

Its a function of an object, like getNaam().

thanks , I think I need a break now what I was doing is fucked up. 

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
https://linustechtips.com/topic/348100-php-undef-function/#findComment-4738555
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×