-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on call $service->helper_function() #131
Comments
I tried to fix, and managed to get some result with the code below, inserting it in class Klein\ServiceProvider (after the function __get). public function __call($key,$param) Please, whoever knows how to contribute to the project by sending revisions, upgrade to have this solution. |
@rafaelwidenet The lack of a |
@Rican7 I honestly really like this example, and although it does not seem "politically correct" represents very well the dynamics of the class. I'm currently using this class in a modular system, which creates fast routines for repeated calls. This is not a "magnificent and perfect way to create a project", but given the cost of agility, is what we are doing. Anyway ... I am seriously considering stopping the future use of this class (updated) to allow the creation of customized routines based functions. Is there any alternative way to use the fast creation of functions? Thank you for your attention. |
@rafaelwidenet Ah, Example 4 just needs to be switched from the service to the response as the caller. Is there a reason why you don't want to just extend the Request, Response, or ServiceProvider classes to add your own methods? Class extension is a much more efficient way of running code (the classes can be op-code cached) versus defining mixin-like methods at runtime. For example, let's add a new method to the Response class: class CustomResponse extends \Klein\Response {
public function respondLoudly() {
$this->append('!!!!!');
$this->send();
}
} And in our app, when dispatching... // Pass in a new instance of our custom Response object
$klein->dispatch(null, new CustomResponse()); |
Hello @Rican7 There is no exact reason for me not to want to extend classes. I'm just not developing the application fully object-oriented. My intention is to use the library Klein to organize and keep safe a systematic programming, but without being "extremely OO". But okay, I found a reasonable solution. Thanks. |
@rafaelwidenet |
I'm trying to create a help function in class $service.
$service->test = function ($str) {
return htmlentities($str);
};
And call with the same parameter:
$service->test('texto');
or with $this (in render file)
$this->test('texto');
But it returns an error.
Fatal error: Call to undefined method Klein\ServiceProvider::test() in C:\htdocs\Labs\index.php on line 25
The function __call does not exist in the class Klein\ServiceProvider.
I think the old version of PHP have enough function __get but now it seems that it is mandatory to use the __call.
The text was updated successfully, but these errors were encountered: