|
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]
|