News for hackers. Stuff that matters.
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @05:28AM (#4198576)
I am not convinced. My argument is not that PHP sucks or that anything else. It is rather that PHP is lexically tied to corner-case development. In that case PHP is very good at some things but not really all that great for others.

PHP started out as being a pre-processor for SGML documents. All PHP code is contained inside SGML program instruction tags. PHP has never changed this, so however it has developed it is still, in essence an SGML preprocessor because even today, all PHP code is contained in SGML PI tags.

This means that your class files, etc. all begin with opening a PI tag....

Now that doesn't mean there aren't some really cool niches for PHP. Using something like PL/PHP and the native XML support in PostgreSQL, you could do some pretty cool stuff. Similarly for lightweight web development there is simply not a better language.

But when you are building a framework where logic may have to be used in non-SGML environments, PHP is a very poor choice. This means when you choose PHP you are limiting yourself to web environments only. Better choices where there is any possibility of escape from the web include Perl, Python, and Ruby.

Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @06:06AM (#4198710)
You've heard of PHP SAPIs right? You can most defiantly use PHP outside of a "web environment". I have PHP daemons managing the sending of email and sms, and another used to manage incoming data that is fed into our local database. These have all ran for years (7+) with no issues.
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @07:25AM (#4198900)
I have used it for all kinds of things. However your code is still embedded in SGML output ;-)
Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @07:40AM (#4198941)
Erm, no it is not.
Re:PHP is much better than what you think by Shish2k on Wednesday July 04, 2012 @08:32AM (#4199113)
Your code doesn't start with a "<?php" tag?
Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @08:43AM (#4199148)
What does that have to do with SGML?
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @08:58AM (#4199210)
It's the opening of an SGML process instruction tag. That's why PHP code is inherently embedded in SGML documents......

That's why the LedgerSMB project uses Template Toolkit with <?lsmb ?> tags (that and [% %] causes problems in LaTeX).

Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @09:07AM (#4199247)
You seem to think you have some understanding of PHP which you blatantly do not. You've made a nonsense assumption based on the choice of tag used by PHP to tell the interpretor to treat the text following the tag as code and not to direct it back out the SAPI.
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @10:10AM (#4199461)
Ummm... I think you are missing my point.

<html> <body> <?mypitag ... ?> </body> </html>

That's an SGML document. It doesn't matter where the PI tag is, or what is in it, it's an SGML document.

<?printstuff

'<html> <body> <p>fun stuff here</p> </body> </html>'

?>

That's still an SGML document.

<?php

# logic goes here

?>

That's an SGML document.

This is not splitting hairs. The reason is relatively subtle.... When you are doing SGML stuff an extra newline or a space in front of the opening tag really doesn't have any effect but if you do any output in binary form, it's a mess.

Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @10:22AM (#4199504)
You are making little to no sense. Sorry, but I've got to give up on this thread.
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @09:24PM (#4201372)
You are looking at it from the interpreter's perspective. I am looking at it from a document semantics perspective and what this means for more complex application environments.

Let me give you an example.

Suppose I have a GUI application that prints some XML fragments to standard output. The most natural way to do this in PHP is to write an XML pre-processor which happens to make decisions based upon operations in the GUI. In other languages you would print to standard output explicitly and the GUI would be primary. In PHP the XML output would be primary and the GUI would be secondary.

In fact your entire GUI is sort of contained in XML fragments to start with.

Re:PHP is much better than what you think by soc88 on Wednesday July 04, 2012 @07:51AM (#4198984)
Yes, the daemon. The actual interpreter is still thrown away every few requests, because it is leaking memory like hell.
Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @07:58AM (#4199002)
"Yes, the daemon. The actual interpreter is still thrown away every few requests, because it is leaking memory like hell."

I'm talking about the CLI SAPI, NOT the Apache SAPI.

Re:PHP is much better than what you think by gnuvince on Wednesday July 04, 2012 @07:43AM (#4198951)
7 years? Really? Cause resource ids in PHP are not recycled, and I figure that at some point during those 7 years, you'd have opened enough connections, files and database handlers that you'd reach the limit of integers and PHP would just abort.
Re:PHP is much better than what you think by xd on Wednesday July 04, 2012 @07:50AM (#4198981)
Hah! Yeah, sorry I should have worded that better. They have been restarted as servers have been upgraded / restarted.
Re:PHP is much better than what you think by dangrossman on Wednesday July 04, 2012 @05:46AM (#4198650)
I don't follow this argument at all. PHP cannot be used outside the web because each source file starts with <?php ? If I wrote a preprocessor for you so that your files wouldn't start with <?php, what would your argument be?
Re:PHP is much better than what you think by einhverfr on Wednesday July 04, 2012 @05:52AM (#4198670)
It would be a lot less of an argument then, and I would be willing to bet that the language would evolve into a far less web-centric area. But in part because of this, if you actually try to do anything outside the web (I have) in PHP, it's not all that pleasant.

Also on the PI tag issue, I would rather keep my PI tags limited to the view or template. it leads to a lot better clarity. and your object classes are no longer technically SGML fragments ;-) This has some nasty side effects if you have a leading space before your opening PI tag and you aren't outputting SGML....

Oh, as a side note, by 'escape from the web' I guess what I really mean is 'escape from SGML-world.' There's a lot of the web that's not SGML-driven and there's a lot of the non-web that is (XML, DocBook SGML, etc).

Bottom line, PHP is a decent tool for working with SGML but it is highly specialized for this. You run into weird things working in SGML mode but not in non-SGML output with things like leading spaces before opening PI tags if you move out of that. Since this is lexically part of the language, I just don't see it changing.