wordpress - PHP: __call not working properly -
i'm having problem creating class called api_widgets
in wordpress using magic __call
function. if simple rename file derp.php
, class api_derp
works without problems.
the next illustration has been stripped of unimportant issue (so if there error other specific fatal error specified in 3rd code block, ignore it).
please maintain in mind know core.php
or api
class' __call
works, renaming widgets.php
or invoking class works fine.
core.php:
class api { function __call( $method, $args ) { $rmethod = "api_{$method}"; if ( !class_exists( $rmethod ) ) { $lmethod = strtolower( $method ); require_once( "{$lmethod}.php" ); } homecoming new $rmethod( $args ); } }
widgets.php:
class api_widgets { private $widgets = array(); function add( $widgets ) { if ( is_array( $widgets ) ) { foreach ( $widgets $widget ) { if ( !in_array( $widget, $this->widgets ) ) $this->widgets[] = $widget; } } else $this->widgets[] = $widgets; } }
api.php:
$api = new api(); $widgets = $api->widgets(); // fatal error: class 'api_widgets' not found in /home4/goldencr/public_html/wp-content/plugins/minecraft-api/api/core.php on line 25 //$widgets->add( 'some_widget' );
extending comment:
though not hinted @ question, seems may not included widgets.php
. seek utilize absolute path prepare that:
require_once( __dir__.directory_separator.$lmethod.".php" );
php wordpress callback naming magic-methods
No comments:
Post a Comment