Answer the question
In order to leave comments, you need to log in
Code organization, pattern, php?
there is some method, in addition to the result of the work of this method, I want to get some kind of information,
for example, here is the code:
public function parserText($a) {<br/>
...<br/>
return $b<br/>
}
public function parserText($a, &$infoMessage) {<br/>
...<br/>
Answer the question
In order to leave comments, you need to log in
You can see how it is implemented by others with errors.
1. Receive an error by a separate method. For example: mysql_error - get the error text of the last operation.
2. And your way with a link. For example: fsockopen - 3 and 4 arguments are passed by reference and contain the error code and text, respectively.
But I like the first one better - no need to change the interface of existing methods.
Well, you can do it like this:
class Parser
{
protected $_messages = array();
public function parse($a)
{
$this->_messages['message key'] = 'some message ...';
/// some code;
return $b;
}
public function getMessages()
{
return $this->messages;
}
}
$parser = new Parser();
$parser->parse($a);
$messages = $parser->getMessages();
You can return an object, and use the toString magic method
. the old code will work (it also worked with the received variable as a string), and in the new code you can access this object and call methods that return additional information. This, of course, is IMHO and you should look at the code =) Good luck!
public function __toString()
{
return $this->output;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question