Reply
ob_start() with callback function
Old 12-20-2007, 12:34 PM ob_start() with callback function
Skilled Talker

Posts: 75
Name: Mattias Nordahl
Location: Sweden
I'm having a bit of trouble using ob_start(). It's possible to call a function before you flush the buffer, with ob_start('my_function'). Then my_function() will be called when you use ob_end_flush(), right?

But how to use it within a class, where my_function() is a method in the class? In the constructor I call ob_start() and in the destructor ob_end_flush(). And there is a method in the class my_function() which should be called. So what parameter should I write in ob_start()?

Thanks
lizciz
lizciz is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-20-2007, 02:56 PM Re: ob_start() with callback function
tripy's Avatar
Fetchez la vache!

Posts: 2,171
Name: Thierry
Location: In the void
From what I understand of the php documentation, you cannot.
It's like the session handler functions.

As you pass the name of the function, you need a "static" defined function to be called.
Wikipedia explain way better than me what a static function is [ http://en.wikipedia.org/wiki/Method_...Static_methods ], but to make it short, a static function is something that is know to be identical to every instances of a class.
As far as I know, there are only static variables available in PHP, no classes.

So, you need to specify a function outside a class, but nothings stops you to make that function call a method of your object.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 12-20-2007, 04:18 PM Re: ob_start() with callback function
Skilled Talker

Posts: 75
Name: Mattias Nordahl
Location: Sweden
I pretty much know what static is and does, but I didn't quite understand what you meant. But it doesn't matter any more. I just realised that using output bufferts was kind of stupid in this perticular case, since they didn't bring any advantage at all, instead I made it more complicated for my self :P

Any way, thanks for your help!
Oh, and by the way. If it's actually possible to call a class method with ob_start() and somebody knows how, please tell me, in case I do need output bufferts any time in the future!
lizciz is offline
Reply With Quote
View Public Profile
 
Old 12-20-2007, 05:09 PM Re: ob_start() with callback function
tripy's Avatar
Fetchez la vache!

Posts: 2,171
Name: Thierry
Location: In the void
What I was saying is that as far as I understand the PHP documentation, you cannot declare a method in a class as the callback.
But you can call a function outside a class, and let that function pass the value to your object
PHP Code:
function obCallBack($src){
  return 
$GLOBALS['myObject']->processOb($src);
}

ob_start('obCallBak'); 
PS: I specified the function to address the GLOBALS variable scope as I'm used to.
I have several globals objects to handle db, authentication, error messages that I address this way to avoid doing global() everywhere in my apps.
No particular need to do it if it's not needed.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 12-20-2007, 05:23 PM Re: ob_start() with callback function
Skilled Talker

Posts: 75
Name: Mattias Nordahl
Location: Sweden
Ah, I see. That was pretty clever
I don't need it right now though, but maybe in the future.
Thanks
lizciz is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 05:59 AM Re: ob_start() with callback function
mtishetsky's Avatar
King Spam Talker

Posts: 1,120
Name: Mike
Location: Mataro, Spain
You can call class methods without having to create class object by calling ClassName::method()
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-21-2007, 06:51 AM Re: ob_start() with callback function
tripy's Avatar
Fetchez la vache!

Posts: 2,171
Name: Thierry
Location: In the void
Yes, I knew that.
But in the case you have several objects of the same class, how does it knows which one to use ?

I believe (but I might be wrong) that in the case of callback used by functions like the ob_start here, or session_handlers redefinition, you cannot use that syntax, due to this issue precisely.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 07:58 AM Re: ob_start() with callback function
Skilled Talker

Posts: 75
Name: Mattias Nordahl
Location: Sweden
I believe tripy is right on this one, since I tried that too myself
lizciz is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ob_start() with callback function
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16219 seconds with 12 queries