0

I believe my class is correct but when I try to echo the output of the class I get an error on line 28: the line " echo 'Your full name ...." is line 28. Any help would be nice

<?php

echo 'Your full name is ' . $person->retrieve_full_name() . '.';

?>

This is where I created the function "retrieve_full_name"

public function __retrieve_full_name() {
    $fullname = $this->firstname . ' . ' . $this->lastname;
    return $fullname;
}/* This ends the Full Name Function*/

the error I get is

Fatal error: Call to undefined method stdClass::retrieve_full_name() in /home/mjcrawle/processlogin2.php on line 28

3
  • Where are you creating this method? How do you retrieve $person? Why is your method name prefixed with __ like a magic method? Commented Feb 26, 2011 at 16:39
  • Why do you have those two underscores up there, before retrieve? Commented Feb 26, 2011 at 16:40
  • 1
    Interesting error. Is your class really called stdClass? Odd name for a personal class. Commented Feb 26, 2011 at 16:49

3 Answers 3

8

your function is called __retrieve_full_name, but you call retrieve_full_name. notice the missing underscores.

double underscores are usually the prefix for php internal/magic functions, i would advise against using them in your function names.

Sign up to request clarification or add additional context in comments.

Comments

3

Your immediate error is due to the fact that you call your method by the wrong name. And:

  • don't use underscores to start a method name
  • don't use underscores in method names at all, if you care for best practice, use camel casing instead retrieveFullName().

Comments

1
public function retrieve_full_name() {

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.