Welcome Guest, Not a member yet? Register   Sign In
How does one correctly address a callback function inside a CodeIgniter library?
#1

I'm writing my own "bbcode" library around PHP's bbcode PECL extension. In some cases, I need to provide a callback function. As I understand it, within an object one passes callback parameters like this:

'callback' => array($this, 'function_name')

So far so good. When I call the code which does this from inside the library, e.g. if I put $this->test() at the end of the constructor, everything works as expected. However, if I try to call this from outside the library, e.g. $this->bbcode->test() from in some controller, I get the following errors:

Code:
**A PHP Error was encountered**
Severity: Warning
Message:  Invalid callback , no array or string given
Filename: libraries/bbcode.php
Line Number: 122

**A PHP Error was encountered**
Severity: Warning
Message:  bbcode_parse(): function `' is not callable
Filename: libraries/bbcode.php
Line Number: 122

needless to say, the callback does not execute.

After bashing my head at this problem for a while, I figured fine, I'll move these callback functions to a helper instead, and that way I can just use their names directly:

'callback' => 'bbcode_function_name'

After reorganizing my code in this manner, I now get the following error:

Code:
**A PHP Error was encountered**
Severity: Warning
Message: Invalid callback 6.7949295043945E-5, no array or string given
Filename: libraries/bbcode.php
Line Number: 176

**A PHP Error was encountered**
Severity: Warning
Message: bbcode_parse(): function `6.7949295043945E-5' is not callable
Filename: libraries/bbcode.php
Line Number: 176

The "function number" does not remain constant with each pageload. At this point, I have no idea what to do...

(more details about the code posted on StackOverflow here)
Reply


Messages In This Thread
How does one correctly address a callback function inside a CodeIgniter library? - by ojensen5115 - 02-27-2015, 04:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB