Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:17:31+00:00 2026-05-26T15:17:31+00:00

Why php functions or classes cannot work like jquery/ javascript plugins? For instance, a

  • 0

Why php functions or classes cannot work like jquery/ javascript plugins?

For instance,

a jquery plugin,

(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);

and then here is how you can use the plugin,

$('.click-me').popup();

or

$('.click-me').popup({widthPopup:300,absoluteLeft:'50%' });

or

$('.click-me').popup({absoluteLeft:'50%' });

as for a php function,

function test($parameter_1 = 100, $parameter_2 = false) {
 ....
}

and you have to call the function like this,

echo test();

or

echo test($parameter_1 = 50, $parameter_2 = true);

or

echo test(10, true);

and it won’t work if you call the function like this,

echo test($parameter_2 = true);

Can you see what I find that php is arbitrary and a bit ‘falling behind’??

Or maybe there is some advanced level of php I haven’t learned yet??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:17:32+00:00Added an answer on May 26, 2026 at 3:17 pm

    What you are describing are two different things. In the JavaScript example, you’re passing associative array (hash, map, JSON, whatever …), but in PHP, you’re using named parameters.

    So the matching code in PHP would be

    function test($parameters) { ... }
    

    and calling it via

    test(array('parameter_1' => 50, 'paramater2' => true));
    

    it’s not as beautiful as the JavaScript version, but it does the same thing. Basically the only difference here is, that in JavaScript, you don’t have to use the array() function to create an associative array, you can just type

    { javascript: "is", cool: true }
    

    and it will work. The PHP alternative here is

    array("javascript" => "is", "cool" => true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there something like serialize/unserialize PHP functions in jQuery? These functions return a string
I have 2 pages one is index.php other is classes.php should not this work
I have the following file structure: cron.php /includes/functions.php /classes/ClassName.php corn.php includes functions.php calls new
Are there any classes/functions written in php publicly available that will take a timestamp,
For our online game, we have written tons of PHP classes and functions grouped
I have written a webservice using the PHP SOAP classes. It has functions to
PHP functions such as 'array_map' take a callback, which can be a simple function
I have added a function to functions.php on my theme. function insertAds($content) { $content
Why can't I use code like this? <?php class NoConstructor { } class ChildWithConstructor
I am wondering if its possible to have Netbeans display PHP Documentation for functions/methods/classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.