Topic Closed
fly06
263 Posts
20.6K Downloads
1 Themes
8 Plugins

I have recently found that the argument ($path) passed to the WhichPage hook differs depending on whether a method is declared in the Addon.ini or not.

[WhichPage]
script = 'Hooks/WhichPage.php'
class = 'My_Plugin_WhichPage'

==> $path is an array ($path[0] is the actual path)

[WhichPage]
script = 'Hooks/WhichPage.php'
class = 'My_Plugin_WhichPage'
method = 'WhichPage'

==> $path is a string (the actual path)

Is that something wanted?

9 years ago#6080

Stano
483 Posts
16.6K Downloads
1 Themes
1 Plugins

Hello fly06, in my understanding of Addon.ini file i think, that if both class and method parameters are specified, then gpEasy creates the object, then calls the method class::method() and finally the object is destroyed. And if the path parameter passed to/from the WhichPage filter, is something you can use(or modify) in the hook handler and it is possible (or necessary?) to return it back to gpEasy. But of course Josh can clarify it to us better.

Edited: 9 years ago#6085

fly06
263 Posts
20.6K Downloads
1 Themes
8 Plugins

I think I've got it.

File: include/tool/gpOutput.php
Method: gpOutput
Method: ExecInfo

$args is an array.

Line 481:

$object = new $info['class']($args);

If no method is specified in the Addon.ini, $args is passed as such (array) to the class constructor which contains the WhichPage hook code. Note also that $args should be passed by reference in this case.

If a method is specified in the Addon.ini, the above code just creates the object and $args is passed to the constructor but is normally not used in this constructor. 

Line 485:

$args[0] = call_user_func_array(array($object, $info['method']), $args );

The call_user_func_array() function considers $args as an array containing the parameters to be passed to the method.

http://php.net/manual/en/function.call-user-func-array.php

If this method is :

function WhichPage($path) {
...
}

Only the first parameter $args[0] will be passed to it by the call_user_func_array() function.

Hence, if we want to be consistent, we should normally have:

$object = new $info['class']($args[0]);
$args[0] = call_user_func_array(array($object, $info['method']), $args );

But anyway, I now understand the issue and this is no longer confusing...

 

Edited: 9 years ago#6086

Topic Closed

 

News

elFinder 2.1.50 in Upcoming Release
12/28/2019

A new release for Typesetter is in the works with a lot of improvements including the ... Read More

Typesetter 5.1
8/12/2017

Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Ennetb├╝rgen (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Websi...

Find out more about our Provider Spotlight

Log In

  Register