爲什麼php函數或類不能像jquery/javascript插件一樣工作?爲什麼php函數或類不能像jquery插件一樣工作?
例如,
一個jQuery插件,
(function($){
// Attach this new method to jQuery
$.fn.extend({
// This is where you write your plugin's name
popup: function(options) {
// Set the default values, use comma to separate the settings, example:
var defaults = {
widthPopup: 500,
absoluteLeft: '500px'
}
var options = $.extend(defaults, options);
var o = options;
var $cm = this.click(function(e){
...
return false;
});
}
});
})(jQuery);
,然後這裏是你如何使用插件,
$('.click-me').popup();
或
$('.click-me').popup({widthPopup:300,absoluteLeft:'50%' });
或
$('.click-me').popup({absoluteLeft:'50%' });
爲一個PHP函數,
function test($parameter_1 = 100, $parameter_2 = false) {
....
}
,你必須這樣調用該函數,
echo test();
或
echo test($parameter_1 = 50, $parameter_2 = true);
或
echo test(10, true);
,如果你這樣調用該函數將無法正常工作,
echo test($parameter_2 = true);
你能看到什麼,我發現PHP是任意的,有點「落後」?
或者也許有一些先進水平的PHP我還沒有學會?
落後?他們不是同一種語言。無法像這樣比較它們。自然的建議是學習語言並根據需要使用它,不要期望它與另一個相同 –
爲什麼橙子不能像蘋果? –