473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return function in class

I had this little bit of code:

function parseTemplateDa ta($file){
$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

and that did what I needed, so I thought I'll put it in a class:

class FOO{

public function parseTemplateDa ta($file){
$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

public function parseEditTag($t ag_content){
....

}

It is, of course looking for parseEditTag *outside* the class. So, I
thought:

$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
"$this->parseEditTag ",
$file);

Which failed.

Then I thought:

$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
EDIT_PAGE::pars eEditTag(),
$file);

Now that calls the function, but doesn't pass in the match.

So I thought I'd try to use create_function . But even if I could
figure out how to pass in the matches, I still can't get it to call the
method in the class.

So, I'm thinking there must be another plan. Or another beer.

Maybe I'm just thinking too perl!

Jeff
Jun 27 '08 #1
2 1309
On Wed, 18 Jun 2008 23:07:40 +0200, Jeff <jeff@spam_me_n ot.comwrote:
I had this little bit of code:

function parseTemplateDa ta($file){
$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

and that did what I needed, so I thought I'll put it in a class:

class FOO{

public function parseTemplateDa ta($file){
$file2=preg_rep lace_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

public function parseEditTag($t ag_content){
...

}
Valid callbacks are:
$callback = 'function_name' ;
$callback = array($instance ofObject,'metho d_name');
$callback = array('ClassNam e','static_meth od_name'));

If you went to the manual for preg_replace_ca llback:
http://nl2.php.net/preg_replace_callback
...and clicked on 'callback', you end up here:
http://nl2.php.net/manual/en/languag...ypes..callback

<?php
class Foo{
function test(){
echo preg_replace_ca llback('/a/',array($this,' funcname'),"aca c");
echo preg_replace_ca llback('/a/',array('Bar',' funcname'),"aca c");
echo preg_replace_ca llback('/a/','funcname',"a cacacaca");
}
function funcname(){
return 'b';
}
}
class Bar{
static function funcname(){
return 'd';
}
}
function funcname(){
return 'e';
}
$f = new Foo();
$f->test();
?>
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #2
Rik Wasmus wrote:
On Wed, 18 Jun 2008 23:07:40 +0200, Jeff <jeff@spam_me_n ot.comwrote:
>I had this little bit of code:

function parseTemplateDa ta($file){
$file2=preg_re place_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

and that did what I needed, so I thought I'll put it in a class:

class FOO{

public function parseTemplateDa ta($file){
$file2=preg_re place_callback(
"/<edit(.*?)>/s",
"parseEditT ag",
$file);
echo $file2;
}

public function parseEditTag($t ag_content){
...

}

Valid callbacks are:
$callback = 'function_name' ;
$callback = array($instance ofObject,'metho d_name');
$callback = array('ClassNam e','static_meth od_name'));

If you went to the manual for preg_replace_ca llback:
http://nl2.php.net/preg_replace_callback
..and clicked on 'callback', you end up here:

http://nl2.php.net/manual/en/languag...types.callback
Thanks for the following example, it's perfectly clear.

And since the next thing on my list to learn was "call_user_func ", I've
already learned that with the 'callback' lesson!

Jeff
>

<?php
class Foo{
function test(){
echo preg_replace_ca llback('/a/',array($this,' funcname'),"aca c");
echo preg_replace_ca llback('/a/',array('Bar',' funcname'),"aca c");
echo preg_replace_ca llback('/a/','funcname',"a cacacaca");
}
function funcname(){
return 'b';
}
}
class Bar{
static function funcname(){
return 'd';
}
}
function funcname(){
return 'e';
}
$f = new Foo();
$f->test();
?>
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4530
by: Phil Powell | last post by:
My first time working with a PHP class, and after 6 hours of working out the kinks I am unable to return a value from the class, so now I appeal to the general audience what on earth did I do wrong this time? This is the code the retrieves the values: if (($hasRegistered || $hasPreRegistered) && !empty($uplinenumber)) { // CHECK TO SEE IF UPLINE NUMBER IS A VALID NUMBER $regNumberGenerator = new RegNumberGenerator($uplinenumber,...
5
8698
by: Murat Tasan | last post by:
so i have a situation that i know cannot be solved directly, and i've already worked around it, but i was hoping to find an explanation as to why this behavior is as it is... i have an abstract class: public abstract class Function { public abstract Number evaluate(Number parameter); } and i have a descendant of that class:
8
3082
by: DaKoadMunky | last post by:
Please consider the following... <CODE> #include <string> using namespace std; typedef int PrimitiveType; typedef string ClassType;
9
1439
by: Rob. | last post by:
I originally thought this was a compiler error but it seems the standard prohibits the code below. Has anyone got any good ideas about how to code around it? class A; class B; class X; class Y; class X
6
2300
by: Busin | last post by:
Classes B, C, D and E are derived from base class A. A* CreateB(); A* CreateC(); A* CreateD(); A* CreateE(); class X { public:
12
3799
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. 1. The Deserialization goes like: #Region " Load "
7
1808
by: nafri | last post by:
hello all, I want to create a function that returns the first element of the Array that is input to it. However, the Input Array can be an Array of points, double, or anyother type, which means the return type of the function depends on the type of the objects the Input array holds. I can have the return type as Object, but it has problems like late binding and more importantly the client has to always Cast it. For example. class...
8
1652
by: WakeBdr | last post by:
I'm writing a class that will query a database for some data and return the result to the caller. I need to be able to return the result of the query in several different ways: list, xml, dictionary, etc. I was wondering if I can use decorators to accomplish this. For instance, I have the following method def getUsers(self, params): return users.query(dbc)
46
3863
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed down from an ancestor or a predecessor or from the past: a legacy of religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF, from ML legatia, from L legare, to depute, bequeath....
10
5619
by: Raj | last post by:
I need a VB function to return array of collections like Private Type Employee empname as string address as string salary as integer deptno as integer End Type dim employees() as Employee
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.