Solved

pointers to static methods

Posted on 2012-03-13
2
287 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 75

Expert Comment

by:käµfm³d 👽
ID: 37718792
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
ID: 37719704
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 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

11 Experts available now in Live!

Get 1:1 Help Now