Re: Accessibility problem with delegates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dave Kok schreef:
> Hi Everyone,
> 
> I have a class with some callback functions and a class that should call
> them. The class with the callback functions initializes the array with
> the callbacks and hands it down to the other class that should call
> them. PHP however forces the callback functions to be public, so the
> other class can call them. This seems rather strange as the callback
> functions have no meaning when invoked arbitrarily. So I was wondering
> whether I am doing something wrong. Could someone comment?

callbacks run from the global scope so whatever is called must be available
i.e. public in the case of methods. so your not doing anything wrong.

if the methods are not static you might consider making the ctor of the
'callback class' private so that only the class itself can create an instance
of itself ... which it then does when creating the callback definitions that
it passes to the class using the callbacks ... so the second class then has
an object on which it can call the relevant functions but no other code
is able to create an instance of the callback class and thereby screw with the
functions designed only to be used in the callback situation.

but that's all probably overkill ... make them public, document their usage, done.

> 
> Regards,
> Dave
> 


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux