Let's say javascript simple callback function could look like that:  function foo(test, clb) {    clb(test); } foo("aaa", function(e) {    console.log(e); });  //Found solution: function processSomething($arr, callable $callback) {    $callback($arr); }  processSomething("xx", function($d) {    echo $d; });
121834
How are callbacks written in PHP?
588
JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function?
53663
My question is told in a few words: Why do you write $E[X]$ in square brackets instead of something like $E(X)$? Probably it is not a "function". How would you call it then? This question also applies for $Var[X]$.
91117
I'm looking for a good approach to manipulate some JS code from within a module call. (Using Drupal 6.)  I have a set of JavaScript functions I need to add to a page. (Regular JavaScript, no jQuery.) Unfortunately they rely on some variables from the page they are shown on. So my current approach is to generate all the JavaScript from within PHP code which results in a whole lot of escaped strings like $output .= '  var url = "'. $url . '";' . "\n";, which is not so nice after 20-30 lines of code.  So I would like to move all the JavaScript code into it's own .js file, and find a way to inject my variables. So far, the only solution I could come up with is putting it in a temporary file, read that, modify and save it to the /files directory. But is there another, more preferred way?
15271
The  lists a few common $A functions and the  references some others that are useful for certain situations.  I can view the $A object in the JavaScript console and get a list of a whole lot more, including some nested such as the $A.util functions.    Is there documentation on the $A functions that are part of the published API (i.e., safe to use)?
5673
I have a function that is effectively a replacement for print, and I want to call it without parentheses, just like calling print.  # Replace print $foo, $bar, "\n";  # with myprint $foo, $bar, "\n";   In Perl, you can create subroutines with parameter templates and it allows exactly this behavior if you define a subroutine as  sub myprint(@) { ... }   Anything similar in PHP?
9415
I have been using AMPscript for a while and I know that there is no way to create custom functions. I was wondering if anybody has come up with an alternative for this?  thanks
40166
Is there a way to use constants in JavaScript?  If not, what's the common practice for specifying variables that are used as constants?
92031
Whats this syntax useful for :       function(String... args)   Is this same as writing       function(String[] args)    with difference only while invoking this method or is there any other feature involved with it ?
31933
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
27396
The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.?    function myJsFunc() {     alert("myJsFunc"); } &lt;a href="#" onclick="myJsFunc();"&gt;Run JavaScript Code&lt;/a&gt;     or    function myJsFunc() {     alert("myJsFunc"); }  &lt;a href="javascript:void(0)" onclick="myJsFunc();"&gt;Run JavaScript Code&lt;/a&gt;
11097
In Python, how do I get a function name as a string, without calling the function?  def my_function():     pass  print get_function_name_as_string(my_function) # my_function is not in quotes   should output "my_function".  Is such function available in Python? If not, any ideas on how to implement get_function_name_as_string, in Python?
98458
I am trying to write a batch. And I have a problem that none of the batch operations callback functions are getting called.  I wrote drupal_set_message at the start of each callback and none of the messages are displayed.  I can get the batch page, but the callback ops aren't called at all.  Here's the code I used:  function mymdoule_node_batch() {     $batch = array(         'title'         =&gt; t("Migrating"),         'operations'    =&gt; array(             array('mycallback_001'),             array('mycallback_002'),         ),         'finished'      =&gt; 'mycallback_finished',         'init_message'  =&gt; t('Initializing...'),         'error_message' =&gt; t('An error occurred.'),     );      batch_set($batch);     drupal_set_message("step: 0"); // this is the only message the system returns }   function mycallback_001(&amp;$context) {     drupal_set_message("step: 1");     $nids = db_select("node", "n")             -&gt;fields("n", array("nid"))             -&gt;orderBy("nid", "ASC")             -&gt;execute()             -&gt;fetchCol(); }  function mycallback_002(&amp;$context) {     drupal_set_message("step: 2");     $nids = db_select("node", "n")             -&gt;fields("n", array("nid"))             -&gt;orderBy("nid", "ASC")             -&gt;execute()             -&gt;fetchCol(); }   P.s. The batch is getting called in form submission.  What's wrong in that?
45178
I was looking for this a while back for JavaScript, but I was wondering a general purpose one exists for all, or most languages.  For example for LaTeX I would put the following in a text box  $f_i^k+10=x$   and it spits out the better formatted version  %%% %% Insert comment describing function here %%% $ f_{i}^{k} + 10 = x $   I can't be the only person on the planet that does not wish to go through a massive .tex file and fix these tedious problems.
4415
A regular function can contain a call to itself in its definition, no problem.  I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no name to refer back to.  Is there a way to do it?  How?
108226
I'm trying to write a function that formats every (string) member/variable in an object, for example with a callback function. The variable names are unknown to me, so it must work with objects of all classes.  How can I achieve something similar to array_map or array_walk with objects?
124175
Is it possible to do something like this  #ifdef SOMETHING #define foo // #else #define foo MyFunction #endif   The idea is that if SOMETHING is defined, then calls to foo(...) become comments (or something that doesn't get evaluated or compiled), otherwise it becomes a call to MyFunction.  I've seen __noop used, but I don't believe I can use that.  EDIT(s):  I don't think I can really use a macro here, because MyFunction takes a variable number of arguments.  Also, I'd like to make it so the arguments are NOT evaluated!  (So doing something like commenting out the body of MyFunction doesn't really give me what I need, as the arguments will still be evaluated)