You are here: Defining a callback Func for preg_replace_callback(), within some class's method « PHP Programming Language « IT news, forums, messages
Defining a callback Func for preg_replace_callback(), within some class's method

Posted by jody.florian on 09/26/03 11:37

Hi,

I'm trying to use preg_replace_callback within a method. The
preg_replace_callback() & mycallback() pair will only be used by this
method, and this method will probably only be called once in the
object's lifetime (so there's no sense in making the callback function
a method of the class...(is there??))

Instead, I wanted to use create_function() to create a make-shift
callback function within the method. (seeing as you can't define a
function within a method). However, it needs to be able to access a
property (or its getter) of the object, and it complains that it's not
within the right scope to access it.

What's the best way of doing this?

class myclass {
....
function mycallback($matches){
return $this->properties[$matches[1]]
}
function mymethod ($subject){
$mystr = preg_replace_callback(
"!{([a-z]+)}!",
array($this,'mycallback'),
$subject
)
}
....
}

This above is the only way I've found of making this work so far.
However, mycallback() I really don't think should have the scope it
does, i would like its definition to stay constrained to mymethod().
any ideas would be greatly appreaciated!

Jody

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация