Solved

pointers to static methods

Posted on 2012-03-13
2
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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