Welcome Guest, Not a member yet? Register   Sign In
[solved] Magic __destruct - Win vs. Mac

Hey everyone,

long time nothing but replies and answers from me, but now I'm back with a problem/question myself.

I just changed my development machine from a Win7 to a MacBook Pro with OS X Lion. And I had thought, everything works well on a UNIX-like system after copy-pasting my files from the Win-machine. But obviously it didn't.

Here's what happens:
There's a library with the magic __destruct function which basically does nothing else than just write some data to the session. Code looks like this

// Check if we got the CI object. If we don't have any, we would trigger errors with
// the upcoming lines.
if ( isset($this->CI) )
    // Log a debugging message so we know what is going on here
    log_message('debug', 'ICF_Message: Library shutting down, saving all messages to session');
    // And save all data into our session
    $this->CI->session->set_userdata($this->_config['session_key'], serialize($this->_messages));

With my Windows machine there are no errors coming up when accessing any page. However, Mac prompts the following

Quote:Warning: include(icf/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Exceptions.php on line 182

Warning: include() [function.include]: Failed opening 'icf/errors/error_php.php' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear') in /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Exceptions.php on line 182

Warning: include(icf/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Exceptions.php on line 182

Warning: include() [function.include]: Failed opening 'icf/errors/error_php.php' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear') in /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Exceptions.php on line 182

I did a debug_backtrace() on line 182 of Exceptions.php and I see a line stating

Quote:[function] => show_php_error
[class] => CI_Exceptions
[args] => Array
[0] => 2
[1] => Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Output.php:445)
[2] => /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/libraries/Session.php
[3] => 672

which actually says: Output sent, cannot change the session anymore.

So now I got two questions:

1) Why didn't I receive these errors on my Windows machine?

2) How can I solve my problem? The idea, why I added the __destruct method, was to wait for all messages to be defined and then just write the session data instead of writing it over and over again whenever a new message is set (the library shall be used for flash-messages).

Maybe somebody, who is not overwhelmed by my long post, can shed some light on this issue - even though I thought I knew how to write PHP and knew all the tricks of PHP.


Not sure about that problem, sorry, but I do know that the mac's version of PHP crypt() does not make use of md5(), which is technically a good thing, except when you are working with legacy code and don't have a choice and need md5 w/crypt(). Took a long time troubleshooting that one when I was using an auth system that used crypt w/md5 to hash passwords. The passwords weren't transferable due to this limitation.

Actually, your first problem is probably because it can't find that file, so it's outputting the error which messes with the headers being sent already.
Make sure /Applications/XAMPP/xamppfiles/htdocs/icf/codeigniter/core/Exceptions.php exists, has proper file and user/group permissions.

Also, check what your document root is set to. It seems it can't find this file due to its relative path.

Failed opening ‘icf/errors/error_php.php’ for inclusion

Thanks for your replies, CroNiX, unfortunately they didn't help at all. I checked all file-permissions, checked all defined constants in index.php. Everything is as it should be.
I also downloaded a clean CI 2.1.1 and let it run with no problems and when I run my current project with the Message-library in autoload.php, it doesn't work. However, removing it from autoload.php or commenting the __destruct()-method will result in no errors.

For me it seems like a strange behavior of the __destruct()-method in combination with the session's library.
The error mentioned above which states it cannot include the file 'error_php.php' is probably because the CI super-object is already (partially) destroyed and therefore the constants and paths don't exist anymore resulting in the error.

I guess, there seems to be some spot I really don't get for fixing the problem.

Would there be a solution to obviate the __destruct()-method completely, because I can't see any at the moment.

Hi PhiTem,

You can also try this:

One can however register the destructor or another method as a shutdown function:
class Logger
     protected $rows = array();

    public function __construct()
         register_shutdown_function(array($this, '__destruct'));
    public function __destruct()
    public function log($row)
         $this->rows[] = $row;
    public function save()
         echo '<ul>';
         foreach ($this->rows as $row)
             echo '<li>', $row, '</li>';
         echo '</ul>';

I would place this in your MY_Controller

@InsiteFX: Tried that one, too, yet it won't change the result in any way.

And right now I'm really at my wit's end...

I think it is the PHP.ini equivalent in your OSX that is causing the problem. Note that the error is just a warning. Probably your Win7 machine has PHP warning messages disabled. Not sure though, I never had used a Mac, but I encountered this type of error before when migrating my PHP projects from Windows to Ubuntu. Hope this helps

I'm not 100% convinced that it may be a problem with my PHP.ini since this should actually be obviated with the ENVIRONMENT switch setting error_reporting to E_ALL for 'development'.

But I'll do some further investigation on the weekend and maybe I will find a solution...


Read this:

PHP generates a warning inside a class destructor when you try to read a file

Thanks @InsiteFX, you're my man Wink

Though it tells me at least: I'm not too stupid for developing things in PHP. However, it's said to see the bug report still being open and not solved.

Anyway, I also think it may be problem due to different PHP versions: ApacheFriends delivers PHP 5.3.1 for Mac OS X based XAMPP and PHP 5.3.8 for Windows based XAMPP. This might resolve in different error handling for that particular error.

Now I just have to find a solution or a workaround which satisfies my (personal) requirements^^

Theme © iAndrew 2016 - Forum software by © MyBB