EDIT: I must have started typing this up just as Brad submitted the above reply. Sorry for any duplication of answers. 🙂
rgelb wrote:Hello, I've been programming for a long time, but never in PHP. So having been given an existing project to fix, I've figured out a couple of things on my own (such as all variables start with $ and the dot is a string concatenation operator), but some of the other things escape me. Maybe some kind soul can answer some of the questions I have:
- It seems that PHP does not require that variables be declared ahead of time. Is this feature optional? Is there a way to force the PHP runtime to require variable declaration (via some sort of keyword, like in Visual Basic did back in the day)?
No. (Certain functions may throw a notice-level error message if you use an unset variable, but it won't stop the script from contining.)
2. It seems that all examples out there show how to connect to MySQL database. How do I connect to Microsoft SQL Server?
I've not worked with MSSQL, but there are a set of MSSQL functions you can use.
3. If the php page is busted (either syntactically or based on input data), sometimes the errors are either ignored or a blank page comes up (not quite sure which one happens when). Is there a way to force PHP runtime to shoot the error out to the web browser?
Start your scripts with:
<?php
// show all errors:
ini_set('display_errors', 1);
error_reporting(E_ALL);
4. Is there an app of some type that will validate the page (e.g. make sure that it is syntactically correct).
Not that I'm aware of, though Zend.com may have something. (I believe if you run your PHP script in command line mode, there is an option to just parse a script without actually executing it.)
5. What is the preferred editor for developing PHP apps on Windows? Is there one that supports intellisense and/or method completion?
There's a pretty big thread on this topic in the Echo Lounge forum here, I believe. Personally, I use HTML-Kit, which has a number of PHP-specific extensions you can add on (and by default includes syntax highlighting for PHP code).
6. I can see from docs that PHP supports OOP. Why is almost all the code that I see on the internet procedural? Is there a problem with OOP in PHP?
PHP4 has pretty rudimentary OOP support. PHP5 has much more complete OOP support. In PHP4 there's not much to be gained from OOP other than being a good way to design and organize your app (which is nothing to sneeze at, mind you). So probably a combination of many PHP servers still being at PHP4, many PHP programmers being self-taught and more inclined to gravitate to procedural programming, and many programs out there probably starting their life in PHP3 or older days, plus the fact that a lot of scripts are just thrown together as quickly as possible (much like a lot of Perl scripts: the goal being just to get it done ASAP); many tend to be done procedurally.
7. How do I debug? Other than print statements and logging to a database? Is there a way to step through a page line by line (like ASP.NET)?
Not with PHP by itself. I think the Zend tools may provide some such debug support, but I'm not sure. (I just try to practice defensive coding practices, and use my own error-handler via the [man]set_error_handler[/man] function to help gather debug data while developing.)
8. mysql_query command only executes a single SQL command. Is there a method that will execute multiple SQL commands?
Other than using stored procedures, I don't think so.