random1 Posted March 10, 2011 Share Posted March 10, 2011 I've written the following code: $mode = 'development'; // 'Development' or 'Public' // Writes a buffer to a file /** * ob_file_callback() * Writes the generated CSS to a file. * @param mixed $buffer * @return void */ function ob_file_callback($buffer) { // stylesheet-public.css is the output generated file $ob_file = fopen('stylesheet-' . $mode . '.css','w'); fwrite($ob_file, $buffer); } $buffer = 'test'; ob_start('ob_file_callback'); $mode is always empty when I run this code. Is it an issue because ob_file_callback is an overridden function? Quote Link to comment https://forums.phpfreaks.com/topic/230185-variables-and-overridden-functions/ Share on other sites More sharing options...
creata.physics Posted March 10, 2011 Share Posted March 10, 2011 or it could be that $mode= NULL? I don't see anywhere in your code where your are defining $mode. if you put $mode = 'public'; i'm sure it would work, if the file exists that is. Quote Link to comment https://forums.phpfreaks.com/topic/230185-variables-and-overridden-functions/#findComment-1185463 Share on other sites More sharing options...
trq Posted March 10, 2011 Share Posted March 10, 2011 Variables created outside of functions do not exist within functions. That's the point of functions, to create stand alone code. If you want to use $mode within your function you will need to pass it in as an argument. (And please, no one mention the globals keyword, globals break encapsulation) Quote Link to comment https://forums.phpfreaks.com/topic/230185-variables-and-overridden-functions/#findComment-1185481 Share on other sites More sharing options...
random1 Posted March 10, 2011 Author Share Posted March 10, 2011 Thanks, that's what I thought. I'll much around with it and wrestle it to the ground. Quote Link to comment https://forums.phpfreaks.com/topic/230185-variables-and-overridden-functions/#findComment-1185488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.