Jump to content

Fatal error: Call to undefined method


mallen
Go to solution Solved by mallen,

Recommended Posts

class MyDisplay 
{

function displayToday()
	{
		
		$today = "Thursday";
		{
		echo $today;
		}
		
		
	}
function displayTomorrow()
	{
		
		$tomorrow = "Friday";
		{
		echo $tomorrow;
		}
		
		
	}

}


$disp = new MyDisplay();


echo $disp->displayToday();
echo displayTomorrow();//fails is I have $disp->


I simplified my code for explanation. One class with two methods. When I try to use the method I get this error. Fatal error: Call to undefined method MyDisplay::displayTomorrow()

Edited by mallen
Link to comment
Share on other sites

your posted code, with the last line change to echo $disp->displayTomorrow();, runs correctly.

 

we will need to see the actual code that produces the error in order to help you with what is wrong with it. you either have a spelling or scope or conditional definition problem.

Link to comment
Share on other sites

1) You need to use the object you instantiated to invoke that method.

2) You don't need to echo if you are echoing in your function.

3) As ginerjm mentioned, you don't need those extra curly braces in your methods.

Link to comment
Share on other sites

They is just too much to post here

 

 

if you have a class definition that contains too much code to post, you are doing something wrong. the only code that's relevant is the class definition, the code making an instance of that class, and the code where you are calling the method/getting the error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.