I wonder if this below is possible in php class object, just as I would do in javascript (jquery).
In jquery, I would do,
(function($){
var methods = {
init : function( options ) {
// I write the function here...
},
hello : function( options ) {
// I write the function here...
}
}
$.fn.myplugin = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist.' );
}
return this;
};
})(jQuery);
So, when I want to call a function inside myplugin
, I just do this,
$.fn.myplugin("hello");
So, I thought, there might be a way to do this in php as well when you come to write a class?
$method = (object)array(
"init" => function() {
// I write the function here...
},
"hello" => function() {
// I write the function here...
}
);
EDIT:
Could it be a class like this?
class ClassName {
public function __construct(){
//
}
public function method_1(){
$method = (object)array(
"init" => function() {
// I write the function here...
},
"hello" => function() {
// I write the function here...
}
);
}
public function method_2(){
$method = (object)array(
"init" => function() {
// I write the function here...
},
"hello" => function() {
// I write the function here...
}
);
}
}