Click here to get back home

finding compile time errors

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
finding compile time errors Jeff 06-13-2008
Posted by Jeff on June 13, 2008, 12:00 pm
Please log in for more thread options
As I'm learning PHP, I'm making a fair number of mistakes in syntax.

In perl, you can turn on reading these errors from the browser by
adding this:

use CGI::Carp 'fatalsToBrowser';

Is there something like this in PHP?

Or do I need to find the php.ini file and look to see where the error
log is?

I spent some time trying to figure out why my class constructor
crashed until I found that I was writing php5 on a php4 setup. What is
most of the established base, is it 4 or 5? I see in the php docs that
some examples use 5.3, considering that the latest stable release is 5.2
I can see how there might be a lot of hair lost!

Any recommendations on creating form elements? I've always used
CGI.pm which handles all the gotchas. Is there anything that comes with
the standard php install? All I really need is radio, select, checkbox
and text... I'm used to writing what I need, but I'm also used to not
reinventing a wheel that was written by someone far smarter!


Is there a standard include_path being used? Are there any standard
extensions for included libararies, generally I'd like them to be seen
*only* by the parent script.



Jeff

Posted by Michael Fesser on June 13, 2008, 12:42 pm
Please log in for more thread options
.oO(Jeff)

> As I'm learning PHP, I'm making a fair number of mistakes in syntax.
>
> In perl, you can turn on reading these errors from the browser by
>adding this:
>
>use CGI::Carp 'fatalsToBrowser';
>
> Is there something like this in PHP?

In PHP error messages are printed to the browser by default (or to the
console if you use the CLI version). With the error_reporting directive
you can control which types of errors should be shown. On a development
machine this directive should be set to E_ALL|E_STRICT in the php.ini.
Also make sure that display_errors is turned on.

> Or do I need to find the php.ini file and look to see where the error
>log is?

By default there is no error log, but you can enable it.

> I spent some time trying to figure out why my class constructor
>crashed until I found that I was writing php5 on a php4 setup. What is
>most of the established base, is it 4 or 5?

PHP 4 is dead, the last support for it will finally end in a few weeks.
After that there will be no more security fixes released. So there's
absolutely no point in writing PHP 4 scripts anymore. Use a recent 5.2
instead.

>I see in the php docs that
>some examples use 5.3, considering that the latest stable release is 5.2
>I can see how there might be a lot of hair lost!

5.3 will introduce two major features that were "backported" from PHP 6,
but it's not released yet. It's not unusual that the manual already
contains short notes or even full documentation about coming features,
because many people already use 5.3 or even 6 for testing.

> Any recommendations on creating form elements? I've always used
>CGI.pm which handles all the gotchas. Is there anything that comes with
>the standard php install? All I really need is radio, select, checkbox
>and text... I'm used to writing what I need, but I'm also used to not
>reinventing a wheel that was written by someone far smarter!

There are various classes and libraries out there for creating and
maintaining forms with PHP. I can't recommend one, since I use my own
code. You could try a Google search.

> Is there a standard include_path being used? Are there any standard
>extensions for included libararies, generally I'd like them to be seen
>*only* by the parent script.

Not sure what you mean.

Micha

Posted by Jeff on June 13, 2008, 1:09 pm
Please log in for more thread options
Michael Fesser wrote:
> .oO(Jeff)

Thanks again for your kind assistance. I feel like I'm getting somewhere.
>
>> As I'm learning PHP, I'm making a fair number of mistakes in syntax.
>>
>> In perl, you can turn on reading these errors from the browser by
>> adding this:
>>
>> use CGI::Carp 'fatalsToBrowser';
>>
>> Is there something like this in PHP?
>
> In PHP error messages are printed to the browser by default (or to the
> console if you use the CLI version). With the error_reporting directive
> you can control which types of errors should be shown. On a development
> machine this directive should be set to E_ALL|E_STRICT in the php.ini.
> Also make sure that display_errors is turned on.


OK, I'll find a check the PHP.ini file as I'm finding that the scripts
silently fail.
>
>> Or do I need to find the php.ini file and look to see where the error
>> log is?
>
> By default there is no error log, but you can enable it.
>
>> I spent some time trying to figure out why my class constructor
>> crashed until I found that I was writing php5 on a php4 setup. What is
>> most of the established base, is it 4 or 5?
>
> PHP 4 is dead, the last support for it will finally end in a few weeks.
> After that there will be no more security fixes released. So there's
> absolutely no point in writing PHP 4 scripts anymore. Use a recent 5.2
> instead.

OK. The box I'm working on was initialized in this year. I expected 5
something. This must just be a preference with my web host (RackSpace).
>
>> I see in the php docs that
>> some examples use 5.3, considering that the latest stable release is 5.2
>> I can see how there might be a lot of hair lost!
>
> 5.3 will introduce two major features that were "backported" from PHP 6,
> but it's not released yet. It's not unusual that the manual already
> contains short notes or even full documentation about coming features,
> because many people already use 5.3 or even 6 for testing.

Thanks. I like the direction PHP seems to be going, but there are so
many "functions"! I'm a bit overwhelmed!
>
>> Any recommendations on creating form elements? I've always used
>> CGI.pm which handles all the gotchas. Is there anything that comes with
>> the standard php install? All I really need is radio, select, checkbox
>> and text... I'm used to writing what I need, but I'm also used to not
>> reinventing a wheel that was written by someone far smarter!
>
> There are various classes and libraries out there for creating and
> maintaining forms with PHP. I can't recommend one, since I use my own
> code. You could try a Google search.

I'm striking out, but am thinking to roll my own also.
>
>> Is there a standard include_path being used? Are there any standard
>> extensions for included libararies, generally I'd like them to be seen
>> *only* by the parent script.
>
> Not sure what you mean.

If I name the included file 'my_functions.php' and put it in the web
path, wouldn't some of this be visible from the web. I just want nothing
to happen if someone hits http://my_domain.com/my_includes.php. Perhaps
I'm worrying about nothing...


How does PHP handle placeholders in MySQL?

I'm used to doing this:

$sql='SELECT some_field FROM some_table WHERE another_field = ? AND
other_field = ?';

When you do this (at least in perl), you don't have to worry about
SQL insertion.

I can't seem to find this, and had stumbled across an example
earlier. Perhaps I should break this question out in a new post...

Jeff
>
> Micha

Posted by Michael Fesser on June 13, 2008, 1:22 pm
Please log in for more thread options
.oO(Jeff)

>If I name the included file 'my_functions.php' and put it in the web
>path, wouldn't some of this be visible from the web. I just want nothing
>to happen if someone hits http://my_domain.com/my_includes.php. Perhaps
>I'm worrying about nothing...

The best and most secure way is to store such files outside the document
root, so that they can't be accessed by a URL.

>How does PHP handle placeholders in MySQL?
>
>I'm used to doing this:
>
>$sql='SELECT some_field FROM some_table WHERE another_field = ? AND
>other_field = ?';
>
> When you do this (at least in perl), you don't have to worry about
>SQL insertion.
>
> I can't seem to find this, and had stumbled across an example
>earlier. Perhaps I should break this question out in a new post...

Have a look at PDO. It's the recommended and most flexible database
interface (installed and enabled by default). The keyword to look for
is "prepared statements".

Micha

Posted by Jeff on June 13, 2008, 3:00 pm
Please log in for more thread options
Michael Fesser wrote:
> .oO(Jeff)
>
>> If I name the included file 'my_functions.php' and put it in the web
>> path, wouldn't some of this be visible from the web. I just want nothing
>> to happen if someone hits http://my_domain.com/my_includes.php. Perhaps
>> I'm worrying about nothing...
>
> The best and most secure way is to store such files outside the document
> root, so that they can't be accessed by a URL.

What I'd like is to be able to specify a library path and when I
require a file the script would know where to look if I just did:
require 'some_file.php';

Lets say I had a directory at the same level as my httpdocs directory
named library. How do I specify that?

I know this bit of pseudo code won't work...

set_include_path('../' . $_SERVER['DOCUMENT_ROOT'] . '/library');

I'm still having trouble with searching the manual, now I'm getting
half the results in Cyryllic!


>
>> How does PHP handle placeholders in MySQL?
>>

<snip>
>
> Have a look at PDO.



Perfect. It looks a *lot* like the Perl DBI module which might be the
best thing that ever happened to perl!

I take it I can do this:

$dbh = new PDO($dsn, $user, $password);
$sql='SELECT * FROM some_table WHERE field_1 = ? AND field_2 =?';
$sth=$dbh->prepare($sql);
$sth->execute('field_1_value','field_2_value');

while($result = $sth->fetch(PDO::FETCH_ASSOC)){
echo $result['some_field'];
}

Is there a die in PHP with an error message? Or should I be using try
catch?

Jeff

It's the recommended and most flexible database
> interface (installed and enabled by default). The keyword to look for
> is "prepared statements".
>
> Micha

Similar ThreadsPosted
Finding errors due to register globals? October 6, 2004, 1:13 pm
Compile time configs September 12, 2006, 11:33 am
compile under AIX 5.1 or 5.2 with IBM VAC? January 3, 2005, 1:06 pm
trying to compile with sablotron September 19, 2004, 5:34 am
how to compile PHP with GD support? May 31, 2005, 7:02 am
Compile PHP 4.4.4 and CentOS September 1, 2006, 5:46 am
DOM XML Compile Problem October 7, 2006, 4:44 pm
compile error December 26, 2006, 11:27 am
Should I yum install php or compile it? July 11, 2007, 3:45 pm
Compile PHP4 with SNMP November 23, 2004, 2:53 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap