Re: [PHP] Accessibility problem with delegates

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.



Relevant Pages

  • Re: Thread Deadlock Problem.
    ... it that are calling callback functions of the xxxdlg class. ... This thread is calling a callback function on every WaitForMultipleObjects ... the WaitForSingleObject() on his handle will deadlock. ...
  • Re: [PATCH 0/6] RFC: Typesafe callbacks
    ... Converting to and from void * for callback functions loses type safety: ... I wasn't too convinced with only irq handler conversion but with other ... Passing NULL as data to callback which takes non-void pointer ...
  • Re: Eliminating UIBUTTONGROUP warning in GUI
    ... and at first I used their Callback functions to get ... I got the warning: "Callback for uicontrol of style radiobutton will be ... my suspicion is that you programmed this using GUIDE and that GUIDE has ...
  • Re: [PATCH 03/19] scheduler: implement workqueue scheduler class
    ... I agree completely with the callback functions, ... scheduler class at all, but to the _thread_. ... proper per-task callback mechanism instead. ...
  • Re: Question about max()
    ... for (var i in this) { ... a property, including an array property. ... The key is the map() function, not the callback. ...