Log in

View Full Version : ATTENION, PHP could get you locked up if not careful...



benslayton
01-11-2008, 05:10 AM
No need to say anything its all here at this link: http://bbspot.com/News/2000/6/php_suspend.html

BLiZZaRD
01-11-2008, 01:17 PM
That's good. I like it a lot.

lainlives
01-11-2008, 09:37 PM
Thats pretty funny.

djr33
01-11-2008, 10:28 PM
We wants it.... our precious...

//foaming at the mouth

Twey
01-11-2008, 11:03 PM
I've always thought people who used PHP by choice should be locked up :p

djr33
01-12-2008, 12:10 AM
Have you infiltrated the police force in Kansas to slowly start spreading that?
Soon, PHP will really be illegal.

Twey
01-12-2008, 12:38 AM
Heh, can't wait!

tech_support
01-12-2008, 02:07 AM
We'd be all forced to use ASP.net

thetestingsite
01-12-2008, 03:46 AM
oh no....not that. :p

djr33
01-12-2008, 08:31 AM
Of course the real question is what defines choice. Is it the choice between using PHP or not scripting such pages at all? Using a language more difficult to find a compatible server (for those using shared hosting, anyway)? Or, simply choosing PHP over ASP.

Twey
01-12-2008, 02:28 PM
Personally I think I'd rather work with ASP.NET and C#. It's a pretty decent language, even if it is a slight rip-off of Java, and thanks to Mono it's portable now too. People have been worrying slightly about whether Microsoft is intending to legally abandon its cross-platformness, though, so I guess that might pose a problem.

Of course, there's always the old standby: CGI :)

tech_support
01-13-2008, 08:35 AM
Personally I think I'd rather work with ASP.NET and C#.
Oh no.... NO.... NOO!!!!!!!!!
Microsoft has gotten into your bloodstream.

But I like Visual Basic. It's a nice language. Easy. I don't really care what everybody thinks about it :p

Twey
01-13-2008, 04:18 PM
But I like Visual Basic. It's a nice language. Easy.If you think Visual Basic is easy then you haven't used it for anything serious :) This is the mark of a bad language: it may seem simple, but attempting to implement complex systems in it quickly becomes a nightmare.

C# is platform-independent, object-oriented, and introspective, with nice features like syntax sugar for getters and setters. It's far from my language of choice, but I'd take it over PHP any day.

Trinithis
01-13-2008, 07:54 PM
When I began to learn PHP for like a day (haven't touched it since because I don't have any use for it for now), I was astonished. There were so many dumb inconsistencies. For example, there might be stuff like:


indexOf(item, fromIndex)
lastIndexOf(fromIndex, item)

(Disclaimer: this is just an example, and not necessarily how PHP does indexOf)

Jas
01-24-2008, 07:27 PM
Interviews with students suggested that PHP use is wide spread around the school, but is particularly concentrated in the geeky nerd population.
Outch!
Anyway, I have to stick up for PHP, because I am finishing up a website coded in it. It's easy to learn, and pretty powerful for such a simple language. But yeah, C# is probably better.

djr33
01-24-2008, 07:34 PM
Easy and it works. Sure, there are many odd problems, but I still find it more friendly than other languages. It's like a calculator that gives the wrong answer 1/10th of the time, opposed to doing all the work by hand and, though harder, getting the right answer. And that's an exaggeration.

Twey
01-25-2008, 06:47 AM
Again, you can only say "it works" if you've never tried to implement a semi-complex design pattern in it. Look at software that attempts to do so (e.g. Propel) and see the ridiculous hacks they have to use to get it working (code generation, in Propel's case).

Jas
01-26-2008, 07:11 PM
Are you talking about using PHP for desktop apps, or websites? For desktop apps it really doesn't work well because it's not meant for that (and they shouldn't have given it the capability). But for the web, I like it.
EDIT: Another point: These forums are in PHP :)

djr33
01-26-2008, 10:46 PM
Exactly. If I wanted to make an video game, I wouldn't use PHP. But that doesn't mean it isn't good for it's every day uses. ;)

Twey
01-27-2008, 05:55 AM
Are you talking about using PHP for desktop apps, or websites? For desktop apps it really doesn't work well because it's not meant for that (and they shouldn't have given it the capability). But for the web, I like it.I'm talking about the language in general, not any specific application of it.
Exactly. If I wanted to make an video game, I wouldn't use PHP. But that doesn't mean it isn't good for it's every day uses.It doesn't necessarily mean that, no, but that doesn't mean it isn't nevertheless true in this case :)
EDIT: Another point: These forums are in PHPAnd I'd bet the code behind them is as hideous, redundant, and unmanageable as that of all the other large PHP applications I've had the misfortune to see.

Jas
01-27-2008, 03:23 PM
How is PHP harder to manage then C# or any other language? To me it sounds like you've only had limited (and bad) experiences with PHP. Maybe you should give it another chance :).
I don't find the language any harder to manage then any other. For example, php is still an OOP language and is divided into classes and functions etc. If you don't use those and, instead, retyped your would-be functions and classes out over and over again, then that would be a mess-- as it would be in any language. Basically, it the coder, not the language, that makes clean code.

Rockonmetal
01-27-2008, 04:12 PM
ok... am i over reacting? its not going to become illegal right? because if it does, i would have to switch to asp... urg... that would be a pain...

BLiZZaRD
01-27-2008, 04:31 PM
LMAO.. yes you are over reacting. It is a spoof. It is a techno-geek page about the computer illiterate confusing php with a drug like PCP, or something.

Don't worry about it. :)

Twey
01-27-2008, 07:38 PM
To me it sounds like you've only had limited (and bad) experiences with PHP.Limited? I've had very extensive experience of PHP, as you can probably tell from my many posts in the PHP section of this forum :p I know all the best practices of PHP, I know its (attempted) strengths and many of its intricacies, and on the basis of that I judge it a bad language.
For example, php is still an OOP language and is divided into classes and functions etc. If you don't use those and, instead, retyped your would-be functions and classes out over and over again, then that would be a mess-- as it would be in any language.Not quite true. PHP is a language that wants to be OO. Unfortunately, its OO support lags far, far behind its competitors'. For example, try this one out for size:
class MyClass1 {
static $var = 5;

public static function get_var() {
return self::$var;
}
}

class MyClass2 extends MyClass1 {
static public $var = 3;
}

print MyClass2::get_var();Expect it to be 3? Oops! It's 5! Inheritance doesn't apply to methods, which still reference the superclass. This means that you effectively can't attach a property to a class to modify its methods' behaviour, a very useful design pattern, unless you actually copy and paste the get_var() method into MyClass2. I've actually run into this issue in live code whilst I was coding a project, and had to (eventually, after hacking around it and ending up with unmaintainably hideous code) rewrite said project from scratch with a different (and less flexible) design pattern.

But OO isn't the only paradigm at which PHP tries and fails. Say you have a two-dimensional arrays/lists of strings, and you want to run two functions over each value, call them sql_escape and slugify, a fairly realistic example, and get back the result. Now, certain languages are better suited to this than others. For example, in Haskell, a language very suited to this sort of thing, we might say:
map (map (sql_escape . slugify)) mylist... which is about as nice as it gets. In Python?
[[sql_escape(slugify(mystr)) for mystr in mysublist] for mysublist in mylist]Not bad. Moving up the scale, we've got JavaScript (1.5+):
mylist.map(function(subList) {
return subList.map(function(str) {
return sql_escape(slugify(str));
});
});Hm, kind of verbose-looking syntax-wise, but conceptually quite elegant. Now, it seems the PHP devs saw all this wonderful "functional" lark and decided they'd quite like to have it in their language too. Unfortunately, their language had several shortcomings that made this quite hard to implement: it had a) no function references and b) no function scope (all functions are global). But hey, the PHP devs are clever folks; they're not about to let a little thing like that stop them. Now, they could, of course, implement function references and scope. However, they decided that this seemed like much too much work, and instead refer to functions by passing around strings containing the function's name (this works because all functions are global, so any function can be accessed from anywhere given its name). Now, this solved the former problem, but what about the latter? Well, some bright spark had a brilliant idea: who needs scopes anyway? If we just scramble the name up, it'll never conflict with another function! Also, if we create the function body as a string, it can even be defined inside another function! So off the devs trotted and happily implemented the monstrosities that are create_function (http://www.php.net/create_function)() and array_map (http://uk2.php.net/array_map)().

Now, bringing this back to our hypothetical situation, the equivalent solution in PHP looks like this:
array_map(create_function('$a', 'return array_map(create_function(\'$b\', \'return sql_escape(slugify($b));\'), $a);'), $mylist);It gets even prettier (if you find sets of three backslashes in a row particularly pleasing) if you try to open another string inside that inner function string. Of course, PHP doesn't have any lexical scoping either -- if you want to pass anything into there, it's going to have to be transformed to string form, suitably (double- or triple-) escaped, then concatenated in there. Can't serialise nicely to a string? You're screwed!

Also worth mentioning are:PHP's complete lack of namespacing, which leads to function names like xsl_xsltprocessor_transform_to_xml (http://www.php.net/xsl-xsltprocessor-transform-to-xml)();
Its complete lack of thread-safety in standard functions (this being a serious drawback to the folks at Apache who've worked hard to bring thread-based performance improvements to their HTTPD 2 webserver, only to have people reject it or turn the threading off by default because PHP doesn't work properly with it);
Silly and inconsistent function naming schemes (htmlentities (http://www.php.net/htmlentities)() vs. html_entity_decode (http://www.php.net/html-entity-decode)()) and argument orders (strpos (http://www.php.net/strpos)($haystack, $needle) vs. array_search (http://www.php.net/array-search)($needle, $haystack)) and conventions (array_search() takes an optional "strict" parameter, but "strict and loose" [case-sensitive and -insensitive] string searches are entirely different functions);
Utterly abysmal support for Unicode.

That turned into a bit of a rant, but I hope I got my point across.
Basically, it the coder, not the language, that makes clean code.Hmm, oversimplification. The coder is, of course, highly important to how neat the final code is, but the language sets the upper bound, and can often also set a "soft" lower bound, making it difficult to write bad code, although probably never impossible.

tech_support
01-28-2008, 02:01 AM
This kinda reminds me of English. It's somehow a mixed up language with some really weird words, but people still use it and won't stop. :p

Nile
01-28-2008, 02:17 AM
Is that real?

Jas
01-29-2008, 10:32 PM
Twey: WOW! I didn't know you felt so strongly. . . lol.

I agree with almost everything you said, but php is still OOP. It may not be the best (as you pointed out), but it's still object oriented. And, all of the cases you pointed out are fairly specific, and you can work around them (but that would definitly be a pain, so another point for you). And, what it lacks in . . . well, what it lacks, it makes up for in its simple functions (for the most part; it's easy to learn). For instance, I looked up your suggestion on Python a while back (I was going to do that instead of PHP), but there was not enough information on it, and being a new coder as I was, I couldn't handle that stuff right out of the gate.

And sorry if I offended you about the limited PHP experience thing (you sounded a bit insulted). I never saw you post code-- only suggestions-- in the php section, so that contributed to my theory. :p I figured you were just really knowledgable with code in general.

Twey
01-29-2008, 11:41 PM
I agree with almost everything you said, but php is still OOP. It may not be the best (as you pointed out), but it's still object oriented.One can say the same of Visual Basic 6 :rolleyes: Its OOP support is a lot better as of PHP5, though, and I was even pointed to this (http://www.php.net/manual/en/language.oop5.late-static-bindings.php), which addresses the problem outlined above as of PHP 5.2. However, the fact that the problem existed in the first place (and took so long to fix, as well, considering it's existed since the genesis of PHP4) just goes to show how tacked-on and poorly thought out PHP OO is. In fact all of PHP is like this: it's actually just a template language that's been a victim of some serious feature creep, it was never designed to be this powerful and it suffers as a result.
And, all of the cases you pointed out are fairly specific, and you can work around them (but that would definitly be a pain, so another point for you).They were just examples. These sort of problems permeate the language. The laughable attempt at being functional, as well, is not specific at all: it affects a lot of situations, I only gave that one as an example. It does illustrate the problem better than a lot of other such possible situations, admittedly, but it's far from unrealistic, and the problem still applies in many other cases.
And, what it lacks in . . . well, what it lacks, it makes up for in its simple functions (for the most part; it's easy to learn).Easy to learn, maybe. Easy to use, no. I've been using PHP for, what, five years or so, but I still have to look up functions because I can never remember what arguments they take or whether their names use underscores or not. Of the functional examples above, I wrote all but the PHP here in this quick-reply box; for the PHP, I had to use a syntax-highlighting editor and test in an interactive interpreter in order to get all the quotes and brackets escaped and balanced properly.
For instance, I looked up your suggestion on Python a while back (I was going to do that instead of PHP), but there was not enough information on it, and being a new coder as I was, I couldn't handle that stuff right out of the gate.Try Dive Into Python (http://diveintopython.org/toc/index.html) and then a Pylons tutorial (http://wiki.pylonshq.com/display/pylonsdocs/Home). There's a lot of very extensive documentation available, it's just not as centralised as PHP's because Python has a lot of modules not included in the central distribution (this is a good thing).
And sorry if I offended you about the limited PHP experience thing (you sounded a bit insulted).No, no problem, I didn't take offence, I was just a little taken aback.
I figured you were just really knowledgable with code in general.Knowledge of how to code in good languages rarely helps in PHP, since it's impossible to implement many of the common design patterns due to PHP's limitations.

Fixed broken link.

tech_support
01-30-2008, 01:58 AM
Easy to learn, maybe. Easy to use, no. I've been using PHP for, what, five years or so, but I still have to look up functions because I can never remember what arguments they take or whether their names use underscores or not.
Strange... I can remember most of them.

Of the functional examples above, I wrote all but the PHP here in this quick-reply box; for the PHP, I had to use a syntax-highlighting editor and test in an interactive interpreter in order to get all the quotes and brackets escaped and balanced properly.
Maybe if you start writing PHP with line breaks you'll find it a lot easier. Most of the code you post in this forum is all one-lined.

djr33
01-30-2008, 02:24 AM
I had to use a syntax-highlighting editor and test in an interactive interpreter in order to get all the quotes and brackets escaped and balanced properly. You did?! What possible reason? It's not like PHP's bracket and other such blocks are any more complex than other languages. If mean, do you need the same interpretor for JS? CSS? I love such an interpretor-- makes life easier-- but PHP is no more complex than the others.

Jas
01-30-2008, 03:50 AM
djr33, Tech_Support help me!!! I am starting to-- dare I say-- come over to Twey's side. :p Just a little, though. I am still going to use PHP for as long as it runs, and I still like it better then other choices. That could be because I haven't given them a chance. But Twey, I really do see your points.

In any case, my website is almost done, and there isn't a chance that I am going to recode it in any other language.
And tech_support is right. I can remember all of the important functions just fine. If I need help with a less common one-- like zipping a file-- I look it up in the reference. That takes a whopping 1/2 a second (close enough :p).

This is a great discussion/debate :)

EDIT: Twey, can I integrate python into my php site? Do they play nicely together? And what features does it have that makes it "better" then php (besides being more OOP)?

Twey
01-30-2008, 12:49 PM
Have you seen this code? Let's post it once again:
array_map(create_function('$a', 'return array_map(create_function(\'$b\', \'return sql_escape(slugify($b));\'), $a);'), $mylist);I suppose I could add some linebreaks, although I'm usually less than happy to do so in the middle of a statement:
array_map(
create_function('$a',
'return array_map(create_function(\'$b\', \'return sql_escape(slugify($b));\'), $a);'),
$mylist);Still looks pretty darn perplexing to me. You're right that PHP's syntax is no trickier than others (in fact it's often easier, what with sprintf() and string interpolation), but in a lot of cases (such as this one) the equivalent code is a lot more complex to handle and maintain, in this case due to the fact that we're enclosing an important block of code in a string.
Maybe if you start writing PHP with line breaks you'll find it a lot easier. Most of the code you post in this forum is all one-lined.Now that's just not true. My general rule is one line per statement. Sometimes I break this for extremely long statements. I'm accustomed to writing inordinately long one-liners in IRC, but here on the forum the only time I write answers on one line is when they consist only of one statement.
Strange... I can remember most of them.Oh, I can remember most of them, but not all of them, and when I forget one I can't make an educated guess because they seem to be assigned pretty much randomly.
In any case, my website is almost done, and there isn't a chance that I am going to recode it in any other language.That's fine, I'm not trying to pull a total conversion on you or anything. Heck, I still use PHP sometimes, for one reason or another. The easiest way to develop with a lot of other languages is by using a framework, for example, and while this leads to much better code in the long run, if I'm just hacking up a quick site or test I tend to use PHP, since it's faster for such use cases.
I still like it better then other choices. That could be because I haven't given them a chance.I suspect you're right.
EDIT: Twey, can I integrate python into my php site? Do they play nicely together?More or less, yes. There's a little .htaccess tweaking to be done to get everything set up and working properly together, but it should be perfectly possible.However, a hosting account that supports FastCGI/WSGI/mod_python is preferred, although you can also run Pylons in bare CGI, which is supported by most web hosts. If your host runs Linux, it probably provides Python (Python is installed by default in most modern Linux distributions). Read: http://wiki.pylonshq.com/display/pylonsdocs/Hosting
And what features does it have that makes it "better" then php (besides being more OOP)?Have a look at Python vs. PHP (http://wiki.python.org/moin/PythonVsPhp) on the Python wiki. The original article was rather biased/uninformed (as you'd expect, I guess), but people have since edited it with various insightful remarks.

Jas
01-30-2008, 08:35 PM
More or less, yes. There's a little .htaccess tweaking to be done to get everything set up and working properly together, but it should be perfectly possible.

How would I actually do it? I read the article you linked to in the edit, and I googled it, but I couldn't find an answer.


Have a look at Python vs. PHP on the Python wiki. The original article was rather biased/uninformed (as you'd expect, I guess), but people have since edited it with various insightful remarks.

It's more of an attempted bash on PHP then anything. And Python doesn't use curly braces "{" ? Preposterous! :p Joking, but I don't like that it relies on the indenting instead. I do indent things that way already, but the curly braces make it easier to see everything. For example:

If (1 == '1'){
echo 'right';
}
echo 'done';

//vs.

If (1 == '1')
echo 'right';
echo 'done'; //this looks like it should be an else statement

I know the code isn't python (it's php :)) but you get the idea. It's just weird. And what if I want to do a loop on one line? Yes, it's bad practice, but I've done it before to save space if it's small. (like while($info = mysql_fetch_array($rows)){$data .= $info;} Never actually used that, but it's a hypothetical example.)

Twey
01-30-2008, 08:55 PM
How would I actually do it? I read the article you linked to in the edit, and I googled it, but I couldn't find an answer.It depends on the setup of your webserver. This (http://wiki.pylonshq.com/display/pylonscookbook/Installing+and+running+Pylons+as+plain+CGI+with+a+no-frills+hosting+service) may be what you're looking for, or perhaps this (http://wiki.pylonshq.com/display/pylonscookbook/Installing+and+running+Pylons+as+plain+CGI+on+a+webhost).
It's more of an attempted bash on PHP then anything.It's true though. :)
And Python doesn't use curly braces "{" ? Preposterous! Joking, but I don't like that it relies on the indenting instead. I do indent things that way already, but the curly braces make it easier to see everything.If you really want to, you can use comments or something:
if foo: #{
doSomething()
#}It looks weird though. :) You get used to not wasting lines on characters to indicate something that's already shown by indentation in any good programmer's code (John excepted :p).
And what if I want to do a loop on one line? Yes, it's bad practice, but I've done it before to save space if it's small. (like while($info = mysql_fetch_array($rows)){$data .= $info;}You can save some noise there by omitting the braces:
while ($info = mysql_fetch_array($rows)) $data .= $info;The Python equivalent to
while ($foo) bar();is:
while foo: bar()Just as convenient. However, most cases in which you'd use a small loop like this in PHP can be accomplished with a functional idiom in Python, such as a list comprehension or a join(); I've never had cause to use one (also, that PHP code will leave you with a very strange $data string).
the curly braces make it easier to see everything. For example:
If (1 == '1'){
echo 'right';
}
echo 'done';

//vs.

If (1 == '1')
echo 'right';
echo 'done'; //this looks like it should be an else statementNot to me -- it doesn't start with "else" :) It may differ from person to person, I suppose.

tech_support
01-31-2008, 06:18 AM
Have you seen this code? Let's post it once again:
How about this?


$myFunc = create_function('$a', 'return array_map(create_function(\'$b\', \'return sql_escape(slugify($b));\'), $a);');
$arr = array(
array('foo','bar'),
array('baz','quuz')
);

array_map($myFunc, $arr);
Looks much better...

Twey
01-31-2008, 12:11 PM
See, that was very silly of me: it was actually meant to be on an array $mylist, array(array('foo', 'bar'), array('baz', 'quux')) was just what I was using for testing :o Edited. It doesn't exactly look much better though. Handling code as strings in its native language is just wrong.

Yes, I could move the function name (hah) to a separate variable, but it's still ugly, and no longer equivalent to the other examples.

boxxertrumps
02-03-2008, 07:21 PM
Easy to use, no. I've been using PHP for, what, five years or so, but I still have to look up functions because I can never remember what arguments they take or whether their names use underscores or not.
I thought only I did that... But it is why i use so few different functions in my scripts.