Page 1 of 1

Using classes causes blank page to be returned

Posted: Fri Aug 29, 2003 3:29 am
by mcp
Hi everyone.

I am a fairly new PHP programmer (previous ASP programmer though) with a very weird problem. I am working on a site that will have different class types that are used to pass information from the DB (mySQL) to the front-end (my code) for display.

While programming the data layer I started getting blank pages being served from the service. After some experimentation I got the script down to the following so that it causes blank pages.

Code: Select all

<?php

class User {
	var $user_id;
	
	var $first_name;
	var $last_name;
}

$joe = new User();

$joe->user_id = 1000;
$joe->first_name = "Joe";
$joe->last_name = "James";

echo("<html><body>");
echo($joe->user_id . " " . $joe->first_name . " " $joe->last_name . "<br>";

echo("Test... test...");

echo("</body></html>");

?>
When I check the apachie logs and nothing is there and the source of the page that is returned is just a generic IE blank page. I even tried to use set_ini to turn on error logging at the begenning of the page, but nothing else was logged.

One thing to note is that I am using PHP on a shared server (SBC) so they could have changed a configuration to make this happen, but I have no idea what.

Also, the service is running PHP 4 (version 2).

Any ideas?

Thanks in advance to anyone that has suggestions... this is causing quite a lot of hair pulling on my side...

mcp

Posted: Fri Aug 29, 2003 4:24 am
by JayBird
There were some syntax errors in your code, i have re-written it for ya

Code: Select all

<?php 

class User { 
   var $user_id; 
    
   var $first_name; 
   var $last_name; 
} 

$joe = new User(); 

$joe->user_id = 1000; 
$joe->first_name = "Joe"; 
$joe->last_name = "James"; 

echo("<html><body>"); 
echo $joe->user_id . " " . $joe->first_name . " " .$joe->last_name . "<br>"; 

echo("Test... test..."); 

echo("</body></html>"); 

?>
the errors were on this line

Code: Select all

echo($joe->user_id . " " . $joe->first_name . " " $joe->last_name . "<br>";
You had an opening bracket, but no closing one! i removed the opening one. Also, you missed out a concatenation operator!

I have tested this code and it works on my machine.

Mark

Posted: Fri Aug 29, 2003 5:01 am
by mcp
Thanks Bech100.

I feel pretty idiotic (as I should... ;-).

Why didn't PHP just report the fact that something wasn't right? Why did it just display a blank page?

I tried adding:

Code: Select all

<?php

set_ini("display_errors", 1);

...

?>
This didn't make the error show up either.

I tried making this fix in the other code (the one that is more complicated) and I am still getting a blank page so something else must be wrong. I'll double check the code again to see if I am doing something stupid like this again.

It just worries me a bit that PHP is not sending me an error like this in the HTML and just dumping a blank page.

Thanks!

chrisbu

Posted: Fri Aug 29, 2003 5:06 am
by JayBird
Strange, are you running on localhost?

Check the following lines in your php.ini

error_reporting = E_ALL & ~E_NOTICE
display_errors = On

Mark

Posted: Fri Aug 29, 2003 5:17 am
by JayBird
also, you code should look like this i think

Code: Select all

<?php 

ini_set("display_errors", "1"); 

... 

?>
check here for info http://se.php.net/manual/en/function.ini-set.php

Posted: Fri Aug 29, 2003 5:43 am
by mcp
Good point, I double-checked the manual and saw that I had typed it wrong in the post.

The machine I am using is a shared host from SBC (an ISP). I called them up because I don't have access to the php.ini and they said that they do turn off display_error by default. They basically gave me the same advice to set it in the script and override the php.ini setting they have.

I added this stuff to the top of the PHP script that is giving me trouble and it still just gives me a blank page.

Code: Select all

<? php

ini_set("display_error", 1);
ini_set("error_reporting", E_ALL);

...
I am going to play around with this a bit more, but if you have any further suggetions that would be excellent.

Thanks!

mcp

Posted: Fri Aug 29, 2003 5:51 am
by JayBird
shouldn't "display_error" be "display_errors"

Mark

Posted: Fri Aug 29, 2003 9:30 am
by volka
using ini_set() will do you no good at this point.
  1. php.ini values set
  2. .htaccess values set
  3. script gets parsed
  4. executions starts
  5. ini_set(...)
  6. and so on
The error occurs at step 3, ini_set has no effect. But if you're allowed to you might change the value with

Code: Select all

php_flag display_errors on
php_flag display_startup_errors on
in your .htaccess file
http://www.php.net/manual/en/configuration.changes.php wrote: When using PHP as an Apache module, you can also change the configuration settings using directives in Apache configuration files (e.g. httpd.conf) and .htaccess files (You will need "AllowOverride Options" or "AllowOverride All" privileges)

Posted: Fri Aug 29, 2003 9:34 am
by JayBird
VOLKA: From the manual

display_errors | "1" | PHP_INI_ALL


PHP_INI_ALL = Entry can be set anywhere

http://se.php.net/manual/en/function.ini-set.php

Posted: Fri Aug 29, 2003 10:40 am
by volka
yes, that's why you can change it in .htaccess ;)

You might change it with ini_set() as well but it has no effects on parse-errors because they occur before ini_set() happens.
Easy to test:
-make sure display_errors is disabled in your php.ini then run

Code: Select all

<?php
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
echo 'done.;
?>
If you include another file after ini_set('display_errors', TRUE); then the parse-errors of this file may show up but not those of the initial script.

Posted: Fri Aug 29, 2003 10:55 am
by JayBird
ah ic

so what is the point of being able to use ini_set('display_errors', TRUE);

What scenario would it be useful?

Mark

Posted: Fri Aug 29, 2003 11:50 am
by mcp
Bech100 == smart
mcp == sloppy

Thanks Bech100! If it wasn't a policy to post when the situation was fixed I would just slink away quietly.

The problem was that I just had the wrong name for "display_errors". I should have noticed something was up when I tried to use ini_get for that value and it came back NULL.

Lessons learned: read slower.

Thanks again.

mcp

Posted: Fri Aug 29, 2003 12:41 pm
by volka
There are not only parse-errors, e.g.

Code: Select all

<?php
ini_set('display_errors', TRUE);
$a = notExistingFunction(1,2);
?>
And not only errors are shown

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
$arr = array(0,1,2);


for($i=0; $i!=4; $i++)
	echo $arr[$i];

echo "<br />\n";

ini_set('display_errors', FALSE);
for($i=0; $i!=4; $i++)
	echo $arr[$i];

echo "<br />\n";
	
ini_set('display_errors', TRUE);
for($i=0; $i!=4; $i++)
	echo @$arr[$i];	
?>