Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
ob_start() with callback function
Old 12-20-2007, 11:34 AM ob_start() with callback function
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
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 Visit lizciz's homepage!
 
 
Register now for full access!
Old 12-20-2007, 01:56 PM Re: ob_start() with callback function
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-20-2007, 03:18 PM Re: ob_start() with callback function
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
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 Visit lizciz's homepage!
 
Old 12-20-2007, 04:09 PM Re: ob_start() with callback function
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-20-2007, 04:23 PM Re: ob_start() with callback function
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
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 Visit lizciz's homepage!
 
Old 12-21-2007, 04:59 AM Re: ob_start() with callback function
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You can call class methods without having to create class object by calling ClassName::method()
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

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, 05:51 AM Re: ob_start() with callback function
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-21-2007, 06:58 AM Re: ob_start() with callback function
lizciz's Avatar
Super Spam Talker

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





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



Page generated in 0.23090 seconds with 12 queries