views:

128

answers:

6

PROBLEM UPDATED, READ BELOW

For some reason my CI fails silently when loading view.
Loading view is simply called from controller

$this->load->view('templates/default.php');

Now. There are some functions in the loaded view that are not defined unless a proper helper is loaded as well. Normally, php would throw an error, but instead it fails silently here. I have no idea why. The template gets outputted till the line containing the undefined function.

It took me long time to realise where my script is failing.

Here's my setup:

  • Windows 7 Ultimate
  • Apache 2.2.15
  • PHP 5.3.2 with following error reporting settings:
    • display_errors = On
    • display_startup_errors = On
    • error_reporting = E_ALL | E_STRICT
  • CodeIgniter 1.7.2

Any ideas why would that be?


UPDATE

After further debugging, it turned out that PHP fails to report any errors when php code is inline with HTML and within the HTML tag. Now this is bizarre.

This returns Fatal Error:

<p><?php echo $bogus(); ?></p>

This doesn't and fails silently:

<p class="<?php echo $bogus(); ?>">paragraph</p>

Why? :O


UPDATE 2

Further investigation showed that if an error_log in PHP is specified, the errors are in fact reported in that file, but still not in the browser... Again, why?


UPDATE 3

Actually my code should be slightly different. Checked another PHP installation on completely different machine and it confirmed the PHP bug. Reported here: http://bugs.php.net/bug.php?id=52040

A: 

Take a look at the error handling documentation, you can get CI to produce its own error reports.

fire
I am aware about CI's error handling but it's got nothing to do with what I'm experiencing. It's php that fails, not CI. The whole rendering process simply stops at the line containing the undefined function and exits silently without returning any errors.
Michal M
Yes it sounds like it cant find the file you are trying to load in the view. Double check the file is in application/views/templates/default.php
fire
It was finding the file properly. Problem appeared during parsing the file. Turns out CI's got nothing to do with it. Read my update.
Michal M
codeigniters error handling won't catch php errors / notices / warnings. It is more like a replacement for throwing exceptions.
Bala Clark
A: 

Look in the /system/application/config/config.php file and /index.php file and check to see what level of error reporting CI is instructing PHP to do.

At the top of the index.php file is the following, which should solve your problem:

/*
|---------------------------------------------------------------
| PHP ERROR REPORTING LEVEL
|---------------------------------------------------------------
|
| By default CI runs with error reporting set to ALL.  For security
| reasons you are encouraged to change this when your site goes live.
| For more info visit:  http://www.php.net/error_reporting
|
*/
    error_reporting(E_ALL);

And in the config file (for completeness) is the following:

/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| If you have enabled error logging, you can set an error threshold to 
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
|   0 = Disables logging, Error logging TURNED OFF
|   1 = Error Messages (including PHP errors)
|   2 = Debug Messages
|   3 = Informational Messages
|   4 = All Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 2;

Which I believe is only for logging, not display.

Kurucu
It's set to 4 and still CI's last msg is:`DEBUG - 2010-06-10 15:14:31 --> Controller Class Initialized` while it should display `File loaded: <path to view>`
Michal M
See my updated answer regarding the `index.php` file.
Kurucu
Turns out CI's got nothing to do with it. Read my update.
Michal M
A: 

Trying to access an object that's not there will cause a silent (blank screen) error.

sitesbyjoe
Only if you've configured PHP to not display that specific kind of error (possibly by disabling all errors through display_errors).
Michael Madsen
A: 

The reason is really quite simple. It's because the browser isn't rendering your error, but if you right click -> View Source, you can see the error in your HTML source code.

<p class="<?php echo $bogus(); ?>">paragraph</p>

would output

<p class="Fatal error: Call to undefined function on line ...">paragraph</p>

or something similar. The browser simply thinks that those words are a collection of CSS classes, so you don't see anything on your screen. It's contained within an HTML attribute.

Lotus Notes
Michal has already indicated that this is not the case in the comments below his question: "Checked that. Source ends at the line before the `bogus()` function."
Kurucu
+1  A: 

Thanks for all the help guys. You would not believe what was the problem!
The browser itself!!! Chrome 6-dev in fact.
It was actually stripping out the invalid html line altogether.

Further testing revealed:

  • IE8 displays the error normally in the browser (which is wrong really as it should be only visible in the source)
  • Firefox 3.6 shows the error in the source
  • Opera 10.53 shows the error in the source

Thanks again for your help.

Michal M
A: 

Without having to change the error display policy for the entire application you could add

ini_set('display_errors', 1);
error_reporting(E_ALL); // Or what ever fits

//If one would like to log the errors one could use
ini_set('log_errors', 1);
ini_set('error_log', FILE_TO_LOG_TO);

to the script in question.

inquam
All sorted now. Check my own answer to see the solution.
Michal M