I wrote my first php code within a newly created drupal module and I got it to work.
Initially it was not working (Drupal would not come up) and I did not know what was wrong so started to take out lines until Drupal finally came up and that is how I discovered which line had the syntax error. Once I knew which line it was I fixed the problem and put it back in the code and drupal came up.
My question is in the future if I have this problem again where Drupal does not come up because of some php code within a custom module erroring off what is a more efficient way for me to detect and fix any php syntax errors?
Thanks,
John
what is a more efficient way for me to detect and fix any php syntax
errors?
A program like notepad++(windows), http://notepad-plus.sourceforge.net/uk/site.htm, TextMate(mac), http://macromates.com/, Dreamweaver(windows or mac), Eclipse (Free - windows or mac),http://www.eclipse.org/webtools/development/ or a similar text editing program with syntax highlighting will show you the easy errors. As for complicated errors, finding them comes form knowledge and experience. The more you do php, the faster you will become familiar with the syntax and can spot things that are not correct.
PHP resource: http://us.php.net/ - the php manual www.lynda.com - with 21+ hours of videos on php in two titles, and 16+ hours of videos on Drupal in three titles.
John Mitchell wrote:
I wrote my first php code within a newly created drupal module and I got it to work.
Firsts are always good.
Initially it was not working (Drupal would not come up) and I did not know what was wrong so started to take out lines until Drupal finally came up and that is how I discovered which line had the syntax error. Once I knew which line it was I fixed the problem and put it back in the code and drupal came up.
The hard way to debug it. :)
My question is in the future if I have this problem again where Drupal does not come up because of some php code within a custom module erroring off what is a more efficient way for me to detect and fix any php syntax errors?
Any number of ways. If you're using apache the error would be in the error.log file. And if you set the php.ini file with a log file or syslog then it would be there. And then there is the PHP display_errors setting that can be set in .htaccess or settings.php file.
.htaccess you would add php_value display_errors 1
Yeah, turning on error reporting helps tremendously -- I hate to develop in an environment with error reporting off.
Also, there is always the old "print 'got here'; exit;" trick which can help when trying to isolate the bad line.
On Wed, Apr 14, 2010 at 4:01 PM, Earnie Boyd earnie@users.sourceforge.netwrote:
John Mitchell wrote:
I wrote my first php code within a newly created drupal module and I got it to work.
Firsts are always good.
Initially it was not working (Drupal would not come up) and I did not know what was wrong so started to take out lines until Drupal finally came up and that is how I discovered which line had the syntax error. Once I knew which line it was I fixed the problem and put it back in the code and drupal came up.
The hard way to debug it. :)
My question is in the future if I have this problem again where Drupal does not come up because of some php code within a custom module erroring off what is a more efficient way for me to detect and fix any php syntax errors?
Any number of ways. If you're using apache the error would be in the error.log file. And if you set the php.ini file with a log file or syslog then it would be there. And then there is the PHP display_errors setting that can be set in .htaccess or settings.php file.
.htaccess you would add php_value display_errors 1
-- Earnie -- http://progw.com
-- http://www.for-my-kids.com
[ Drupal support list | http://lists.drupal.org/ ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
If you are worried about syntactic errors (rather than logical ones), you can also run your code through php's lint.
$ php -l mymodule.php
Unfortunately, this only handles one file at a time, but it will tell you if the code can be included at all.
Best of Luck, CM Lubinski - --- http://cmlubinski.info
William Smith wrote:
Yeah, turning on error reporting helps tremendously -- I hate to develop in an environment with error reporting off.
Also, there is always the old "print 'got here'; exit;" trick which can help when trying to isolate the bad line.
On Wed, Apr 14, 2010 at 4:01 PM, Earnie Boyd earnie@users.sourceforge.netwrote:
John Mitchell wrote:
I wrote my first php code within a newly created drupal module and I got it to work.
Firsts are always good.
Initially it was not working (Drupal would not come up) and I did not know what was wrong so started to take out lines until Drupal finally came up and that is how I discovered which line had the syntax error. Once I knew which line it was I fixed the problem and put it back in the code and drupal came up.
The hard way to debug it. :)
My question is in the future if I have this problem again where Drupal does not come up because of some php code within a custom module erroring off what is a more efficient way for me to detect and fix any php syntax errors?
Any number of ways. If you're using apache the error would be in the error.log file. And if you set the php.ini file with a log file or syslog then it would be there. And then there is the PHP display_errors setting that can be set in .htaccess or settings.php file.
.htaccess you would add php_value display_errors 1
-- Earnie -- http://progw.com
-- http://www.for-my-kids.com
[ Drupal support list | http://lists.drupal.org/ ]
On Thu, Apr 15, 2010 at 9:13 AM, CM Lubinski cmc333333@gmail.com wrote:
If you are worried about syntactic errors (rather than logical ones), you can also run your code through php's lint.
$ php -l mymodule.php
Unfortunately, this only handles one file at a time, but it will tell you if the code can be included at all.
Command line fun to the rescue:
$ find ./ -type f -exec php -l {} ;
That command: 1. Finds items in the current directory and subdirectories 2. That are "type f" (i.e. files) 3. And executes a new php -l function on each file it finds
I keep that in a script called "phpchecker" in my ~/bin/ directory and frequently use it prior to making a commit or a tag on code.
Cheers, Greg