fluvly Posted September 23, 2009 Share Posted September 23, 2009 I found this line of code, but I can't understand the syntax of it: register_shutdown_function(array($this, 'close')); I read on the online documentation that the register_shutdown_function calls a shutdown function before the script ends; it's not the actual function that I have a problem with, but the syntax of the shutdown function between parenthesis: array($this, 'close') What does that mean? What happens in this case when the register_shutdown_function is called? What function does it call? An array? I thank in advance anyone who is able to help. Link to comment https://forums.phpfreaks.com/topic/175228-solved-what-does-this-line-of-code-do/ Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 It calls a class method. The first element in the array identifies an instantiated class object ($this, the instantiated object in which the shutdown function is defined), the second element identifies the method by name ('close') Link to comment https://forums.phpfreaks.com/topic/175228-solved-what-does-this-line-of-code-do/#findComment-923549 Share on other sites More sharing options...
fluvly Posted September 23, 2009 Author Share Posted September 23, 2009 Thank you for the explanation, and now one side of it is clear. But I still don't understand why those 2 elements are put in an array... shouldn't there be just the name of the function? Something like: register_shutdown_function($this->close); It might be a banal doubt, but I'm new to php and I really can't understand the "array" bit. Thanks! Link to comment https://forums.phpfreaks.com/topic/175228-solved-what-does-this-line-of-code-do/#findComment-923560 Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 Thank you for the explanation, and now one side of it is clear. But I still don't understand why those 2 elements are put in an array... shouldn't there be just the name of the function? Something like: register_shutdown_function($this->close); It would simply be the name of a function if the code was procedural, but it's not - it's OOP. Using an array like this is the standard mechanism that PHP uses for a lot of callbacks when the method is defined within a class. Link to comment https://forums.phpfreaks.com/topic/175228-solved-what-does-this-line-of-code-do/#findComment-923569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.