function

PHP: Define function with variable parameter count?

Is there a way to define a function in PHP that lets you define a variable amount of parameters? in the language I am more familiar with it is like so: function myFunction(...rest){ /* rest == array of params */ return rest.length; } myFunction("foo","bar"); // returns 2; Thanks! ...

Powershell advanced functions: are optional parameters supposed to get initialized?

filter CountFilter($StartAt = 0) { Write-Output ($StartAt++) } function CountFunction { [CmdletBinding()] param ( [Parameter(ValueFromPipeline=$true, Mandatory=$true)] $InputObject, [Parameter(Position=0)] $StartAt = 0 ) process { Write-Output ($StartAt++) } } $...

Calling a python function from bash script

I have an "alarm email" function inside a python module. I want to be able to call this function from a bash script. I know you can call a module using 'python ' in the script, but I'm not if you can or how you would call a specific function within the module. ...

Removing a function at runtime in PHP

I know this question seems hacky and weird, but is there a way to remove a function at runtime in PHP? I have a recursive function declared in a "if" block and want that function to be "valid" only in that "if" block. I don't want this function to be callled outside this block. I found out runkit_function_remove but runkit isn't enable...

When to use a Class vs. Function in PHP

The lightbulb has yet to go on for this... I'd really love an easy to understand explanation of the advantage to using a class in php over just using functions. Here's a simple example of the thought I'm having now and am wondering if a class is more efficient: Say I have a mini calendar widget that I've built in php. I'm thinking ...

PHP: Functions have no idea variables even exist.

I've noticed an annoying peculiarity in PHP (running 5.2.11). If one page includes another page (and both contain their own variables and functions), both pages are aware of each others' variables. However, their functions seem to be aware of no variables at all (except those declared within the function). My question: Why does that h...

functions not working the way they should in sudoku solver?

I'm trying to make a 4x4 sudoku solver in Python (I'm only a beginner!) and while trying to define a function to clean up my code somewhat, I ran across some strange behavior I don't really understand. Apparently, there's a difference between this: sudoku = "0200140000230040" sudoku = map(lambda x: '1234' if x=='0' else x, list(sudoku)...

Javascript problem

I'm a noob in Javascript but here is my problem: I'm cleaning up some PHP-files. Some of them contain Javascript functions which I want to transfer to a separate xxx.js file. Most of them are working fine again but one causes me trouble. I think because of the punctuation (the ' and "). Here's the script as it shows up IN the PHP-file: ...

Is there a way to overload a function based on different Result type in Delphi?

http://stackoverflow.com/questions/442026/function-overloading-by-return-type has a very detailed answer on the rational on function overloading by return type, and from what I can see Delphi does not allow this, but are there any workarounds to overload a function based on different return type in Delphi? ...

as3, function active after 3 seconds

Hi, I have 2 functions going in as3: function blueDownBounce (e:MouseEvent):void { var blueDownY:Tween = new Tween(blue, "y", Regular.easeOut, -49, -19, 1, true); } blue.addEventListener(MouseEvent.MOUSE_OVER, blueDownBounce); function blueUpBounce (e:MouseEvent):void { var blueUpY:Tween = new Tween(blue, "y", Bounce.easeOut, ...

Virtual functions table offset

Hello. I would like to ask you on what does the offset of the table of virtual functions for a class depend? I mean, from what I've read it at least depends on compiler, but does it varies from class to class? Edit: by offset I mean the position of the table relative to the address of the owner object. Edit: example code: void **vtabl...

Deciphering a function

A short time ago, a gentleman posted this function in an answer to a question. As a learner, I am interested in understanding the function. However, I can't get it to work as is. The poster did not say that he had tested the function, so it could have been a "conceptual" post, meant to show direction. OTOH, I may not be invoking it c...

copying functions located in instances

Here's some (simplified) code for what I'm trying to do: class a: pass class b: def printSelf(self): print self instOfA = a() instOfB = b() instOfA.printSelf = instOfB.printSelf instOfA.printSelf() <__main__.b instance at 0x0295D238> When I call instOfA.printSelf(), it prints self as being instOfB. But I want sel...

php function with a while-loop

Hi I have a function that generates a random combination. my function looks like this: function random_gen($length) { $random= ""; srand((double)microtime()*1000000); $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_list .= "abcdefghijklmnopqrstuvwxyz"; $char_list .= "1234567890"; // Add the special characters to $char_li...

Can I require class-functions only if the class is instantiated in php?

Trying to improve my code's agility and loading time, I thought of doing this, so that the functions would be required only if the class was instantiated. class User { public function __construct() { require('all_user_fns.php'); } } Inside all_user_fns.php will reside all User class's functions. Is that feasible (...

How can you dynamically load Javascript functions using Ajax?

(Rhetorical Question) I ran into a bizarre scenario today where I wanted PHP to update how the javascript behaved on-the-fly. It was irritating, here is what I tried... /* * ajax-php-javascript-function-loader.php * * this gets called by AJAX and defines or re-defines the * definition of dynamicDoStuff() */ <script type="text/ja...

How to round to nearest X minutes with PL/pgSQL?

How I can round to nearest X minutes? Here's my attempt: DECLARE _stamp ALIAS FOR $1; -- timestamp _nearest ALIAS FOR $2; -- minutes (integer) _minutes decimal; _ret timestamp; BEGIN _ret := date_trunc('minute', _stamp); SELECT EXTRACT (minute FROM _ret)::integer INTO _minutes; IF (_minutes % _nearest < (_nearest / 2)) ...

Can you alter a Javascript function after declaring it?

Let's say I have var a = function() { return 1; }. Is it possible to alter a so that a() returns 2? Perhaps by editing a property of the a object, since every function is an object? Update: Wow, thanks for all the responses. However, I'm afraid I wasn't looking to simply reassign a variable but actually edit an existing function. I am t...

jquery call back function

i have a form and it validates and submit successfully. all i want is to call back function as "success" when the form has successfully submitted. here is what i have so far but no luck: $(document).ready(function() { $("#form1").validate({ rules: { email1: {// compound rule required: tru...

How to avoid out parameters?

I've seen numerous arguments that using a return value is preferable to out parameters. I am convinced of the reasons why to avoid them, but I find myself unsure if I'm running into cases where it is unavoidable. Part One of my question is: What are some of your favorite/common ways of getting around using an out parameter? Stuff alon...