I have the error
Call to undefined method Exception::message()
inside the object calling
Utils::message()
(I am catching the Exception and replacing by the message)
The file containing this object is included (require_once) by the top file together with another file defining Utils.
So my question is why the method of Utils is not recognized. All classes are included before the main code. Does the inclusion order matter? Any other hints?
EDIT. My Utils class:
class Utils {
private static $count;
private static $aggregateCount, $time, $last, $previous;
...
public static function message () {
echo "\n Count: ", self::$count++, " ";
$array = func_get_args();
foreach ($array as $entry) {
if (is_array($entry)) {
echo print_r($entry);
} else {
echo $entry;
}
}
}
...
}
And here is the function using the class:
public function updateManyWithId ($schema, array $bundle) {
foreach ($bundle as $hash) {
$id = $hash[ID_KEY];
$hash = $this->_adjustId($schema, $hash);
try {
$this->update($schema, $id, $hash);
} catch (Exception $e) {
Utils::message("Cannot update hash: ", $hash, $e->message());
}
}
}
$e->message()Is the problem. That refers to a class calledExceptionwhich is expected to have a method calledmessage, but yourExceptionclass does not have that method.Look at the constructor of your
Exception. You're passing in a message when you throw it, perhaps you're looking for$e->getMessage().Read here: http://www.php.net/manual/en/exception.getmessage.php
To summarize, consider this:
Note that the standard usage of
getters/settersis to usegetPropertyandsetPropertyas the method name that returns/sets that property.