Solved

pointers to static methods

Posted on 2012-03-13
2
282 Views
Last Modified: 2012-03-14
Hi, I defined pointers to 3 different static methods

 if ($cond1)
   $crtrow = function () { return DD::cuctrowch(); };

 if ($cond2)
   $crtrow = function () { return DD::cuctrow(); };

 if ($cond3)
   $crtrow = function () { return DD::cuctrowp(); };


class DD
 static function  cuctrow($row)
 {

 }
 static function  cuctrow($row)
 {

 } 
..
..
}

Open in new window


each of those function requires a parameter. however when i call $crtrow($row)

i am getting an error that function

DD::cuctrow() requires parameter, which I am passing
0
Comment
Question by:Rozamunda
2 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
My guess is that you are saying "function () ..." which means you aren't declaring that the anonymous function takes a parameter at all. Sure, the function that is being called in the body of that anonymous function does, but you have not provided a way for the anonymous function to receive a parameter.

In short, instead of "function ()..." try "function ($row)...".

...and you'll also need to pass that parameter.

e.g.

if ($cond3)
   $crtrow = function ($row) { return DD::cuctrowp($row); };

Open in new window

0
 
LVL 10

Accepted Solution

by:
Derokorian earned 500 total points
Comment Utility
You could also use the use () method and referencing. Like so:
if ($cond1)
   $crtrow = function () use (&$row) { return DD::cuctrowch($row); };

Open in new window

See http://php.net/manual/en/functions.anonymous.php for more info
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now