--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support
--- Begin Message ---
Of course, my apologies.
I've simplified it from the actual code and also removed the string
parameter as the object one is the problem:

// create the model and replacer function
> $model = new $modelName();
> $replacer = curryModelReplacer($($model);
> // ...
>
> /** Curries model_replacer. */
> function curryModelReplacer($model) {
>    return create_function('$matches', "return modelReplacer($model,
> \$matches);");
> }
>
> /** The callback for preg_replace_callback. */
> function modelReplacer($model, $matches) {
>    // do the replacement...
> }
>

So effectively I want to create a new anonymous function wrapping
modelReplacer which has the $model parameter already set. The problem is
obviously that I can't put $model in the string.
Is there a better alternative approach for currying in PHP that will enable
me to bind an object to a parameter?

TIA,
--rob


On 9/4/07, Richard Heyes <[EMAIL PROTECTED]> wrote:
>
> > I have a function which is my callback for preg_replace_callback - and
> it
> > needs to be able to access a string and an object outside of itself.
> > When I call create_function I can insert the string, but without
> serializing
> > the object I can't figure out how to make it available to the function
> > without making it global, which seems nasty.
> >
> > I've tried 'currying' the function - creating a new function out of it
> with
> > the string and object parameters bound, but have the same problem - I
> can't
> > get the object into the function.
> > Can anyone point me towards a good solution? I guess I could also create
> a
> > class with the one function, but that seems a wee bit messy to me.
>
> It would be helpful if you could post a bare-bones example.
>
> --
> Richard Heyes
> +44 (0)800 0213 172
> http://www.websupportsolutions.co.uk
>
> Knowledge Base and HelpDesk software
> that can cut the cost of online support
>



-- 
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

--- End Message ---
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to