• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

PHP annoyances

CareBear

NLC
NLC
I guess this doesn't really belong here but I need to vent a little right now :p

Each time I use PHP I fail to see what people think is so great about it, unless they just don't know any better :confused2.
You waste hours trying to figure out why your code is misbehaving because you can't do any serious kind of debugging and why on earth someone would think that using variables without declaring them first is a good thing is beyond me.

Then when you finally finish you have the fun of figuring out why it won't work on the server because you used version 4.3.0.1.2.3 but the server has version 4.3.0.0.2.4.
And then to top it off each host gets to decide which extensions they'll include and which they won't: "oh.. you meant XSLT. No, we don't actually provide that extension on that server. Can't you work around it?".

I know most people here hate Microsoft but at least they deliver a decent product with ASP.NET. No versioning problems, a great development enviorment and decent documentation.
 
If you code right, then you have no problems, plus it is very powerful if you know what you are doing.
 
Well...I'm sure ASP.NET is good too, but PHP is more popular...the popularity of it increases it's popularity. It's viral. More people use PHP, so more hosts support, so more people learn PHP because it's more popular, so more hosts support it, so more people create scripts in php, so more people learn it, etc.

Also, it's very easy to use and FREE, which boosted the popularity in the first place.
 
imo, the majority of people just use pre-written php code.
just a mather of changing some vars are there ya go.
 
actually most hosts support it because.... its free. ASP you need IIS and a number of other expensive MS tools. Why bother when you can download linux, apache, php and mysql.
 
are you saying, carebear, that languages like perl or asp, etc, never have new releases or security upgrades? you could use your arguments for any programming language, not just php because you may have a little trouble figuring it out.

at least - and this is only one of many positives - when you do make a coding errer (your fault, not the language's fault), it tells you what line to look at, to at lest give you a pretty good idea where your error might be... not so with perl, where all you get is an internal server error... good luck!!
 
lol, yeh, perl is very hard to debug... and not to mention, slowest. i also think declaring a var before using is not quite needed, i dont see a very important reason behind it besides memory space, it only adds addtional line to your code...
In my experience with all others, php is so far the best and easiest language there is today. no programming skills required. it has the best community on the net, you can learn it easily on your own. the only sad thing is, most companies would still prefer microsoft technologies and in the open source world, when you get stuck in serious problem, who you gonna call for support?
 
are you saying, carebear, that languages like perl or asp, etc, never have new releases or security upgrades? you could use your arguments for any programming language, not just php because you may have a little trouble figuring it out.
Bug fixes, security issues and the like are very different from introducing new functionality or changing existing functionality.
As far as I can tell PHP doesn't have the concept of patches, if they fix something it's something that will be included in a future version and won't be applied to older builds at all.
Pick 10 random servers and 5 will have 5 different versions of PHP 4.3.x on it.
Why should I have to remember that file() works on any PHP 4 build, that file_get_contents() only works on PHP 4.3.0 and higher and that file_put_contents() will only work in PHP 5, which packages are compiled into PHP by default and which are add-ons which may or may not be available but are in the documentation none the less. Know which OS PHP will be running on because some functions behave differently on different OS'es?

at least - and this is only one of many positives - when you do make a coding errer (your fault, not the language's fault), it tells you what line to look at, to at lest give you a pretty good idea where your error might be... not so with perl, where all you get is an internal server error... good luck!!
I was talking about tracking bugs, not syntax errors. You won't see any line numbers for that, just not the output you expected.
What's your tactic for dealing with logic errors rather then syntax errors? echo/print all your return values or log them to a file and then see if you can get a vague idea of which function isn't doing what it's supposed to do?
That's not debugging, that's wandering around in the dark hoping you'll crash into the light switch by chance. Debugging is setting a breakpoint on a line, stepping over your code line by line, being able to examine your script as it's running, look at the variables and their content as it's running.

i also think declaring a var before using is not quite needed, i dont see a very important reason behind it besides memory space, it only adds addtional line to your code...
So you'd get an error when you have something like:
PHP:
$text = ...;
...
echo $txet;
Unless you're all exceptional people I make typo's :p & probably the most common place I have it happening in is forgetting the $this-> to access a member variable in a class.
The only way you can spot it now is if your script doesn't behave, no runtime error, no nothing.

I don't think PHP is necessarily bad, just that it's a chaotic mess of dozens of different build each with its own little quirks and (virtually) none of the debugging support you'd expect from a modern language.

(Edit: someone pointed me to Zend Studio which would solve the debugging problem. They need to advertise it more :))
 
Last edited:
Originally posted by CareBear
So you'd get an error when you have something like:
PHP:
$text = ...;
...
echo $txet;
thats like saying
PHP:
Dim myvar As String
myvar = ...
if you do it properly with quotes you wont get an error.
$text = "...";
 
Originally posted by kabatak
thats like saying
PHP:
Dim myvar As String
myvar = ...
if you do it properly with quotes you wont get an error.
$text = "...";
I was just making a point, not writing working code :p

And you missed it actually.. the point was that "$text" was misspelled in the last line so it would output nothing, no matter what value $text had.
From PHP's point of view there's no error since it doesn't have a clue which are actual variables and which might be a typo.

(Yes I know you can put error_reporting(E_NOTICE); but besides looking hideous it won't catch everything either)
 
lol, yeh i missed it but same way still.
PHP:
<%
dim text
text="..."
response.write(txet)
%>
though Im not sure if ASP has an option explicit thing, the code above should work by default unless you declare option explicit. which i think makes ASP handy, so I guess you win, lol.
 
Last edited:
though Im not sure if ASP has an option explicit thing, the code above should work by default unless you declare option explicit. which i think makes ASP handy, so I guess you win, lol.
Regular ASP does have an Option Explicit "thing" :). Although ASP.NET really doesn't compare to regular ASP since you're programming in VB.NET or C# and not vbscript anymore.

On the PHP debugging issue Komodo seems to be another decent product. I'm running trial issues of both right now so we'll see how that goes :).
 
Actually, just yesterday I was having problems because I was trying to output a var that didn't exist yet (I forgot to set it...), so, I can see your point. But, in the long run, it's much easier to figure out where I went wrong than it is declaring every variable I use. Most PHP is so simple, declaring variables would just waste time, and cause noobies more hardships.

As for debugging, I've never known a real debugger in any scripting/programming I've done. It's easy enough to find logic error just echoing your vars as you go along.

The upgrades and stuff, most hosts will be using a fairly new version of PHP, and after that won't ever revert back to an old version. So, if you code for a slightly older version of PHP, you have no problems. Mostly, from what it seems to me, the new versions have more functions...that's about it. You can always code the functions yourself.
 
You could just turn error reporting to E_ALL and it'll tell you when you've got a missing var somewhere. Better then E_NOTICE :p Other then that, what else wouldn't it catch? :eek:
 
Last edited:
Other then that, what else wouldn't it catch? :eek:
Things like:
PHP:
error_reporting(E_ALL);

class Foo {
  function Foo($data) {
    $fooData = $data;
  }

  var $fooData;
}

$FooTest = new Foo("this will never get displayed");
echo $FooTest->fooData;
It's obvious in this case but once things get a little more complex forgetting $this-> can be really annoying to track down and I tend to forget it every now and then which is why I usually use an "m_" prefix to class variables to have a mental trigger that I'm using a member variable.

(Nice site btw :) If you need any submissions for the C# or .NET categories and I have some spare time I could write something up if you like. I tend to be better at explaining how to solve a problem then to come with my own topic though :confused2)
 
Last edited:
carebear, just learn php properly and you won't have all these headaches. vbulletin isn't having any trouble making thousands upon thousands of dollars distributing an entirely php-based forum, are they?
 
Originally posted by CareBear
(Nice site btw :) If you need any submissions for the C# or .NET categories and I have some spare time I could write something up if you like. I tend to be better at explaining how to solve a problem then to come with my own topic though :confused2)
Thanks :D In the middle of a new PHP :p backend.

As to your example, would C# give an error? I'm thinking it wold give a "blah blah is declared but never used" or something, but then again I suck at .NET :p Oh wait, can't do anything with an undefinded var right? Bleh, I dunno. :doh!:
 
Originally posted by keith
carebear, just learn php properly and you won't have all these headaches. vbulletin isn't having any trouble making thousands upon thousands of dollars distributing an entirely php-based forum, are they?
Excuse me if I'm not up to par with all you "leet" people who consider editing plain text configuration files and using command line interfaces to be the height of computer knowledge.
Tracing debug output from your code has it uses but as far as productivity goes it doesn't come close to an IDE with a decent debugger. If you can't see the value of setting breakpoints or inspecting your variables as your code runs (or an at design time compiler for that matter) then you haven't done any kind of large project.
I'm not putting PHP down, it works well (obviously) but where you see advantages of not declaring variables before use and having loosely typed variables ("1" == 1), from my point of view it doesn't overcome all the disadvantages and it causes problems cause I'm used to different.
It's the same kind of arguement I'd have with a VB programmer who doesn't see a point in having a case sensitive language where I just think it's normal.
We'll just have to agree to disagree and not drop down to questioning the other's skill. :rolleyes:

In the middle of a new PHP backend
I never said PHP isn't any good :p

As to your example, would C# give an error?
You'd need to declare the variable before use and give it a value or the compiler will complain.

PHP:
string Text;
Console.WriteLine(Text);
will give a compiler error saying Text is declared but never intialized.

PHP:
string Text = "";
Console.WriteLine(Text);
will make it stop complaining :).

PHP:
string Text;
if (SomeCondition == true)
  Text = "";
Console.WriteLine(Text);
will cause a compiler error as well though since if the condition isn't true then Text remains unassigned.
 
Last edited:
Originally posted by kabatak
lol, yeh, perl is very hard to debug... and not to mention, slowest. i also think declaring a var before using is not quite needed, i dont see a very important reason behind it besides memory space, it only adds addtional line to your code...
In my experience with all others, php is so far the best and easiest language there is today. no programming skills required. it has the best community on the net, you can learn it easily on your own. the only sad thing is, most companies would still prefer microsoft technologies and in the open source world, when you get stuck in serious problem, who you gonna call for support?

Actually perl is much easier to debug than php IMO. Also it just as fast as php is most cases.

Declaring your variables should be in PHP. It good coding. All the languages I've worked with other than PHP require you to declare variables before using them, and because of this you will get an error if you make a typo with a variable because it will be undefined.
 
Back
Top