mallen Posted June 5, 2014 Share Posted June 5, 2014 (edited) 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 June 5, 2014 by mallen Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 echo displayTomorrow() has to fail as you've showed it. It has to be written just like your displayToday call. Question. Why the extra braces in each of your methods? Quote Link to comment Share on other sites More sharing options...
mallen Posted June 5, 2014 Author Share Posted June 5, 2014 (edited) If I type it just like this echo $disp->displayTomorrow(); I get Fatal error: Call to undefined method MyDisplay::displayTomorrow() Edited June 5, 2014 by mallen Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 5, 2014 Share Posted June 5, 2014 $disp->displayTomorrow(); Works for me. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 Why don't you show us that code that fails. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 5, 2014 Share Posted June 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
Maq Posted June 5, 2014 Share Posted June 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
mallen Posted June 5, 2014 Author Share Posted June 5, 2014 Thanks. I just tested that sample code I posted and saw that it worked. Now I need to know why is doesn't on my project. They is just too much to post here. Something must be conflicting. Works without $disp-> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 Can you show the snippet that "works without $disp.>". It would be very interesting to see what you think is working. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 5, 2014 Share Posted June 5, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 I asked for a 'snippet'. Not the whole code. Quote Link to comment Share on other sites More sharing options...
Solution mallen Posted June 6, 2014 Author Solution Share Posted June 6, 2014 I got it solved. I was adding methods below the closing bracket of the class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.