Universal Safe Text Encoding

Status
Not open for further replies.

drwool

Seniorius Lurkius
10
I've just built a web software app implemented mainly in Javascript, which involves a lot of user-entered text which must be stored and retrieved from a server-based database. So user-entered text is handled initially by Javascript, which generates HTTP POST calls to pass the text to a PHP function, which in turn must generate MySQL commands to store it in the database. The whole process has to work in reverse to get text from MySQL back through PHP which puts the text into a JSON string for return to the Javascript program.

Well, since the user can enter any text whatsoever, including any punctuation, symbols pasted in from a word processor, extended ASCII, foreign alphabets and symbols in Unicode, etc., the problem becomes how to encode it in such a way that nothing in the text will have any syntactic meaning in Javascript, PHP, or MySQL. That turned out to be a hair-puller for me. I tried all sorts of built-in Javascript and PHP encoding functions, as well as various ones I found on the web, but could not find anything existent that wouldn't stumble over SOMEthing.

So I invented my own text-encoding technique. My requirements:

* Encoded text must consist of nothing but the ASCII alphabetic letters and digits 0-9, plus a single "escape" character.

* Must be able to faithfully encode ANY text that's valid in Unicode and then decode it to be identical to the original.

* The application must be able to designate ANY character code as the escape (except letters and digits), so as to avoid collisions with whatever languages or systems it needs to be compatible with.

* The encoded text should be basically readable by a human (assuming it's written primarily using the ASCII alphabetic characters).

* It should be possible for any program to decode the text without having prior knowledge of what character was used as the escape during encoding.


Maybe there's something already out there that does all of this. If so, I'd like to know about it, even though it'll mean I've just re-invented the wheel. If not, and if folks are interested, I'll be happy to share what I've come up with.
 

wallinbl

Ars Legatus Legionis
14,319
Subscriptor
drwool":3euiv4u7 said:
Can you guys expand on your answers a bit? Ravensroke, I know what UTF-8 is but don't know what you mean by "UTF-8 + prepared statements."

Richard, I don't use eval. Don't know exactly what you mean by "parameterize your queries."

http://us2.php.net/manual/en/pdo.prepar ... ements.php

That covers it. The point is to avoid using string concatenation to build queries. This lets the SQL engine know precisely what is query text and what is a variable/parameter. It protects you from things like single quotes or other special characters in user input that inadvertently or maliciously alter the query text.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
drwool":3ahxhpiq said:
universal escape mechanism

Does not exist.
And, I'm of the belief that it's impossible.

It's not impossible in the sense that I would be shocked if someone produced one, it's impossible in that I would doubt it were universal regardless of the amount of testing and proofs supplied. The proofs would require a complete analysis of each browsers full text handling in every conceivable way, followed by every web server, followed by ever web development language, followed by every filesystem and database interaction, and in all possible combinations of the above.

Because you can never be sure some fucking dimwit didn't toss in an exotic escape character that causes something somewhere to process things just a little differently in just the right circumstance.

Use parameterized queries and more than half your problem disappears. Now all you're left with is html/javascript injection issues, something which you can filter as the target (web browsers) have a definitive grammar.
 

drwool

Seniorius Lurkius
10
Topham, suppose that the encoded text consists entirely of the ASCII alphabetic and numeric characters, plus one escape character which can be designated by the programmer to be ANY character code that's valid in Unicode, so as to avoid problems with whatever languages/platforms you happen to be working with at the moment.

I think the ability to choose your escape is what makes it universal. I'm not saying that a particular encoded string would be universally acceptable to every conceivable piece of software you might run it through. The point is you choose your escape based on the platforms you're actually working with.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
drwool":3s24y102 said:
Topham, suppose that the encoded text consists entirely of the ASCII alphabetic and numeric characters, plus one escape character which can be designated by the programmer to be ANY character code that's valid in Unicode, so as to avoid problems with whatever languages/platforms you happen to be working with at the moment.

I think the ability to choose your escape is what makes it universal. I'm not saying that a particular encoded string would be universally acceptable to every conceivable piece of software you might run it through. The point is you choose your escape based on the platforms you're actually working with.

I suppose you think I was being sarcastic, however I wasn't. If mysql (just to pick on them) has an undocumented escape sequence that 'always works' then it doesn't matter how many times you swizzle the character strings being passed to it there will always be a way to slip through a screw with the query.

A long time ago a company called Hayes dreamt up a validly interesting idea. By using a special character sequence and specialized timing they could embed commands in a regular data stream without actually escaping them in the traditional sense. This would allow them to handle every ascii character in any conceivable sequence and never have any issues. It's virtually fool proof. They did such a good job of it they patented the idea and collected royalties from most other manufacturers of modems. However, the patent increased costs and made it difficult to turn a profit when the price of modems dropped quite low (relatively speaking). A number of the low-end manufacturers decided that the sequence of symbols and letters was it's own escape sequence and therefor they could ignore the timing issue and just watch for a longer stream of characters.

Instead of watching for <delay>+++<delay> they could watch for the full hangup sequence instead, but without the delays +++ATH0<cr> was exceedingly rare. It was so rare they predicted nobody would ever trip over it by accident. The modems were, generally, smart enough to only recognize the sequence if it originated from the host computer, and not the other end, so they decided the sequence was perfect. The users could hit the 'Hangup' button in their terminal programs and the modems would hangup, but they could transmit all the data they wanted and there would never be a problem. Life was good. For a few minutes anyway.

Turns out a software developer realized that the pirate boards were starting to use low-end modems instead of Hayes or USRobotics. Since he was trying to cut down on piracy of his application he'd decided to add the sequence "+++ATH0<cr>" into his application. Sooner or later somebody would try transmitting it to a pirate board and they'd get hung up on during the attempt, or, and this was the best part, the upload would succeed. Subsequent downloads would fail though.

It wasn't perfect, if a pirate board was using decent modems then they wouldn't have a hangup issue during download, and the user could upload it wherever he wanted if he also was using a decent modem, but it did cause a ripple when the executable showed up corrupted/truncated in various places.
 

drwool

Seniorius Lurkius
10
Well, more words have been spilled here about whether this thing is worthwhile than the thing itself takes up. So what the heck, I'll just post the code. It may not cure cancer and bring about world peace, but it solved a problem I had. If it looks useful to you, take it and use it; if not, don't.

Below is the Javascript implementation. I've done a PHP version as well.


Code:
//
// ZvvyCode:  Universal safe text encoding method
//
// 		By David R. Woolley
// 		Thinkofit, Inc.
//
//
// ZvvyCode is a text encoding method that converts virtually any text into a format that can
// be handled by virtually any programming language without the danger of there being characters
// embedded in the encoded text that have syntactic meaning in the language. An encoded string
// consists only of the ASCII letters (a-z and A-Z) and digits (0-9), plus one special escape
// character which is designated at the time of encoding and may be anything other than the
// ASCII letters and digits. An encoded string can be decoded without advance knowledge of the
// escape character, because the escape character is read from the beginning of the encoded string.
//
// The original ASCII letters (a-z and A-Z) and digits (0-9) are kept in their original form.
// ALL other characters, including spaces, punctuation, extended ASCII codes, Unicode characters,
// etc. are converted to their hexadecimal character codes bounded on each end by a uniform
// escape character. The escape character may be any character except the ASCII letters and digits,
// so you can choose an escape character that will not cause trouble in your application.
//
// An encoded string begins with an 8-character sequence consisting of two instances of the escape
// character used in encoding the string, the letters "zvvy", and two more instances of the escape
// character. The decoder reads these characters to determine (1) whether the string is, in fact,
// a ZvvyCode string, and (2) what character to interpret as the escape character for the decoding
// process.
//
// If the first eight characters do not follow this pattern exactly, or if the characters in the
// positions designated for the escape characters are ASCII letters or digits, then the string
// is considered to be NOT ZvvyCode, and is returned as-is, without decoding.
//
// Example: Suppose you choose a slash as the escape character to encode this text:
//
// 		I said, "Joe's bag is 3/4 full!"
//
// The ZvvyCode encoding would be:
//
//		//zvvy//I/20/said/2c//20//22/Joe/27/s/20/bag/20/is/20/3/2f/4/20/full/21//22/
//
//	Note that it doesn't matter that the original text has a slash in it, even though the slash
//	is to be used as the escape character. The slash is simply converted to /2f/.
//
//	The escape character does not have to be a visible character at all. It can be, for example,
//	0 (ASCII null), 127 (ASCII del), 27 (ASCII esc), 255 (the last extended ASCII character)
//	or even a large Unicode character value. The only restriction is that it cannot be one of
//	the ASCII upper or lower case letters or numeric digits.
//


//
//	toZvvy: Convert a string to ZvvyCode encoding.
//
//	Arguments:
//		str		String to be encoded
//		escChr	Character code to use as the escape character, given as a numeric value.
//		(E.g., 92 or 0x5c to use backslash as the escape.)
//		MUST NOT BE A LETTER (a-z, A-Z) OR DIGIT (0-9). Any other character code is valid.
//
//	Returns:
//		ZvvyCode encoded string
//
//
function toZvvyCode (str, escChr) {

	var i, chr;
	var lth = str.length;
	var escChrStr = String.fromCharCode(escChr);

	// Begin with two escape characters, the "zvvy" identifier, and two more escapes.
	var rs = escChrStr + escChrStr + "zvvy" + escChrStr + escChrStr;

	for (i = 0; i < lth; i++) {
		chr = str.charCodeAt (i);
		if ((chr >= 0x30 && chr <= 0x39) || (chr >= 0x41 && chr <= 0x5A) || (chr >= 0x61 && chr <= 0x7A)) {
			// Copy a-z, A-Z, and 0-9 as-is.
			rs += str.charAt(i);
		}
		else {
			// Output a hex character value surrounded by escape characters.
			rs += escChrStr + chr.toString(16) + escChrStr;
		}
	}
	return (rs);
}


//
//	fromZvvyCode: Convert a ZvvyCode encoded string back to its original value.
//
//	Arguments:
//		str		String to be decoded
//
//	Returns:
//		Object with two properties:
//			text:	Decoded string
//			error:	-1 if successful
//				 0 if the string was determined to be not encoded and is returned unchanged
//				 2 or greater if the encoded string is malformed
//
//	An encoded string is considered malformed if any of the following occur:
//		* A value enclosed between two escape characters is not a valid hexadecimal number
//		* An opening escape character is not matched by a closing escape - i.e., the string ends
//		  before a terminating escape character is found.
//
//	In case of a malformed string, the returned object will contain:
//		text:	As much of the string as could be decoded before the error was encountered
//		error:	Position within the string where a problematic escape sequence began
//

function fromZvvyCode (str) {

	var i, escPos, escVal, escChr, escChrStr;
	var lth = str.length;
	var retobj = { "text": '', "error": -1 };

	if (lth < 8) {
		// If string is less than eight characters, it cannot be ZvvyCode, so return as is.
		retobj.text = str;
		retobj.error = 0;
		return (retobj);
	}

	escChr = str.charCodeAt (0);	// First character should be the escape character used to encode this string
	escChrStr = str.charAt(0);
	if ((escChr >= 0x30 && escChr <= 0x39) || (escChr >= 0x41 && escChr <= 0x5A) || (escChr >= 0x61 && escChr <= 0x7A)) {
		// First character is a letter or digit, not a valid escape character -- means this is not ZvvyCode so return as is.
		retobj.text = str;
		retobj.error = 0;
		return (retobj);
	}
	if (escChrStr != str.charAt(1) || escChrStr != str.charAt(6) || escChrStr != str.charAt(7) || str.substring(2,6) != "zvvy") {
		// First 8 characters do not follow ZvvyCode pattern -- means string is not ZvvyCode, so return as is.
		retobj.text = str;
		retobj.error = 0;
		return (retobj);
	}

	i = 8;		// Start decoding after the first eight characters
	while (i < lth) {
		escPos = str.indexOf(escChrStr, i);
		if (escPos < 0) {
			// No more instances of the escape string found, so append remainder of string and we are done.
			retobj.text += str.substring(i);
			return ( retobj );
		}
		retobj.text += str.substring(i, escPos);	// Append all regular characters up to where escape was found
		i = escPos + 1;						// Point to first character beyond the escape
		escPos = str.indexOf(escChrStr, i);	// Find terminating escape
		if (escPos >= 0) {
			escVal = '0x' + str.substring (i, escPos);
			if (isNaN(escVal)) {
				// Value in the escape sequence is not a valid number
				retobj.error = i - 1;
				return (retobj);
			}
			retobj.text += String.fromCharCode(escVal);
			i = escPos + 1;
		}
		else {

			// Escape sequence was started but string ended with no terminating escape found.
			// This indicates a malformed string.
			// Return decoded text up to the beginning of the unterminated escape sequence,
			// and set error value to the character position where the escape sequence began.

			retobj.error = i - 1;
			return ( retobj );
		}
	}
	return (retobj);
}
 

Pont

Ars Legatus Legionis
26,160
Subscriptor
Below is the Javascript implementation.
Wait... the string only gets escaped if the user is running a browser with javascript enabled? That's not how injection attacks work. The malicious users aren't running a browser at all. They're running a script pretending to be a browser. "Hello Mr. WebApp. I'm Internet Explorer. Please DROP TABLES. Thanks."
 

drwool

Seniorius Lurkius
10
This wasn't written to protect against malicious users. For that, you might need to take additional steps. The point of this is just to put user-written text into a form that can be transferred from Javascript through HTTP POST to a PHP program to MySQL without errors if the user text happens to include quotes and colons and Unicode characters or whatever else someone might innocently type or paste into a text box.

As I mentioned, I've got PHP versions of the encoder and decoder, as well.
 
Blacken00100":3vr7o6i0 said:
As usual: mysql_real_escape_string is fucking wrong, don't use it.
Yeah, I thought you needed mysql_Real_escape_string. Next version of PHP will have mysql_REAL_escape_string.

Seriously, prepared statements are easy. Someone else worked hard to make sure they're correct and secure. Let that someone else work for you! (Like those late night commercials "Why work for money? Let your money work for you!" except this time it's for real.) The API is right in front of you. Even if you don't care about security or performance, it's so much easier to just use prepared statements than come up with a blob of custom escaping code that doesn't work correctly and you have to maintain. There's no excuse to not.
 

drwool

Seniorius Lurkius
10
Actually, forget I ever said anything about MySQL. MySQL is irrelevant. This isn't meant to hacker-proof your code. It's just a way to convert any arbitrary text into a form that you can send through whatever programming languages or data exchange protocols you happen to be dealing with without stumbling over a quote or curly bracket or angle bracket or semicolon or whatever and then restore it to its form original at the other end.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Your libraries should handle your escaping, not your code. If you put a curly bracket inside a string in a JSON block, it treats it as a string because it's not stupid. If you're writing a JSON library, you should be adhering to the JSON standards for escaped text.

You are solving a problem that it appears nobody actually has. I would suggest that this should be a call to re-think why you're doing it, because passing around text really is a solved problem.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
The only reason to do this is if you are writing the library (JSON/XML) or driver (database and the like)
And when doing so you should only care about your domain, not anyone else's

Your attempt is *dangerous*. Fundamentally unsound, the classic example of a little knowledge being a dangerous thing.

Further more it's a waste of time since other (smarter) people have already done it for you in the right places.

Treat this as a learning experience (if a painful one)
 

drwool

Seniorius Lurkius
10
Well then, to complete the learning experience, could you guys explain how you would do this? I freely admit there may be a better solution than the one I've come up with.

The task is to implement a questionnaire with an arbitrary number of questions, with the user interface handled by Javascript/JQuery. The questions accept free-form text answers - no restrictions on what can be typed or pasted in. The user's answers must be stored in a MySQL database. The user must be able to exit at any point, come back later, and have the questionnaire repopulated with whatever answers he has already entered.

Given that, what method(s) do you use to get the user's text to and from the database?
 

topham

Ars Legatus Legionis
13,756
Subscriptor
While I am not a proponent of mixing code and html, this is the amount of encoding one should do with form data:
Code:
<html>
<head></head>
<body>
This is a test form
<br />
<form name="bookdata" method="get">
<input name="BookTitle" size=60 maxlength=60 value=<?php echo '"'.htmlentities( $_GET['BookTitle']).'"'; ?> />
<br />
<input type="submit" name="submit" value="Post Book" />
</form>
</body>
</html>

BookTitle round trips to the webserver and back without corruption.
Functions other than htmlentities() may be used, like htmlspecialchar() for example.

Storing it in a database isn't any more complicated than using parameterized queries.


If you receive errors when submitting characters to a form, you are doing it wrong. If you are filtering the characters client side in any way you are doing it wrong


The solution to handling bad input is to handle it appropriately in all instances. Appropriate can be rejecting the data outright, or accepting it as-is. If you are massaging the data because not massaging the data is causing you problems you are doing it wrong.

Badly formed JSON? Reject it. badly formed XML? Reject it. Random characters? Accept it, or reject it based on your business requirements. You should not have any technical requirements preventing you from accepting the characters.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
Here's a stupid database example where all the book titles are inserted into the database.
Note: No error checking is performed, destination table is 'test' with columns 'id' and 'title'. id is auto-incrementing integer value.
You can shove almost whatever quotes and ampersands and whatever else you throw at it and it'll retain it and display it properly.

(Exception is Unicode characters due to the fact the browser translates it and PHP doesn't convert it. (or, my mysql doesn't because i didn't enable something).
Unicode will show up as it's entity code however, no errors will be generated, databases won't crash, etc)). (And it's late, and I'm sick and not going to chase it down right this second).
Code:
<?php 
   $db = new PDO('mysql:dbname=test;host=localhost','','');
   if ($_GET['BookTitle'] != '') {
   $updateStmt = $db->prepare('INSERT INTO test (title) VALUES(:title)');
   $updateStmt->bindParam(':title', $_GET['BookTitle'], PDO::PARAM_STR,60);
   $updateStmt->execute();
   }
  ?>
<html>
<head></head>
<body>
This is a test form
<br />
<form name="bookdata" method="get">
<input name="BookTitle" size=60 maxlength=60 value=<?php echo '"'.htmlentities( $_GET['BookTitle']).'"'; ?> />
<br />
<input type="submit" name="submit" value="Post Book" />
</form>
<table>
<?php 
  $stmt = $db->prepare('SELECT * FROM test;');
  $stmt->execute ();
  foreach ($stmt->fetchAll() as $field ) {
     echo '<tr>';
     echo '<td>'.htmlentities($field['id']).'<td>';
     echo '<td>'.htmlentities($field['title']).'<td>';
     echo '</tr>';
  }
  $stmt->closeCursor();
  ?>
</table>
</body>
</html>
 

topham

Ars Legatus Legionis
13,756
Subscriptor
For those who care (all -2 of you).

mysql - set to utf-8 at the database and table level.
apache - set content type to serve utf-8 if in html
php - output content-type header, meta tag,

use htmlspecialchars instead of htmlentities, htmlentities corrupts utf-8 depending on the version of php. Nice.

set form to use utf-8 on submit.

http://malevolent.com/weblog/archive/2007/03/12/unicode-utf8-php-mysql/ decent resource.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
technophile":16xwjd2r said:
topham":16xwjd2r said:
use htmlspecialchars instead of htmlentities, htmlentities corrupts utf-8 depending on the version of php. Nice.
The solution to that is the same as every other solution to a PHP problem: don't use PHP. I can't see any reason to use it in the face of so many other worthwhile solutions.
:rolleyes: There are a zillion business reasons to use php for any number of things.
 

topham

Ars Legatus Legionis
13,756
Subscriptor
technophile":2yar2di5 said:
topham":2yar2di5 said:
use htmlspecialchars instead of htmlentities, htmlentities corrupts utf-8 depending on the version of php. Nice.
The solution to that is the same as every other solution to a PHP problem: don't use PHP. I can't see any reason to use it in the face of so many other worthwhile solutions.

Meh, I've used several other languages with utf-8 issues; a long with a database that seemed to think UTF wasn't standard enough for them and they made it 'better'. (read "incompatible" for some weird-ass bizarro reason).
 

technophile

Ars Legatus Legionis
23,768
hanser":37pqdott said:
technophile":37pqdott said:
topham":37pqdott said:
use htmlspecialchars instead of htmlentities, htmlentities corrupts utf-8 depending on the version of php. Nice.
The solution to that is the same as every other solution to a PHP problem: don't use PHP. I can't see any reason to use it in the face of so many other worthwhile solutions.
:rolleyes: There are a zillion business reasons to use php for any number of things.
The only "business reason" I can think of is "our programmers are too stupid to learn anything else".

Single page/side project/hobbyist thing? Sure, use PHP, whatever. Something that might conceivably actually have to scale/be used internationally? No. Just no.
 
technophile":e4lijgqi said:
hanser":e4lijgqi said:
technophile":e4lijgqi said:
topham":e4lijgqi said:
use htmlspecialchars instead of htmlentities, htmlentities corrupts utf-8 depending on the version of php. Nice.
The solution to that is the same as every other solution to a PHP problem: don't use PHP. I can't see any reason to use it in the face of so many other worthwhile solutions.
:rolleyes: There are a zillion business reasons to use php for any number of things.
The only "business reason" I can think of is "our programmers are too stupid to learn anything else".

Single page/side project/hobbyist thing? Sure, use PHP, whatever. Something that might conceivably actually have to scale/be used internationally? No. Just no.

Like Facebook?
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
technophile":2t6iu15z said:
The only "business reason" I can think of is "our programmers are too stupid to learn anything else".

Single page/side project/hobbyist thing? Sure, use PHP, whatever. Something that might conceivably actually have to scale/be used internationally? No. Just no.
Mediawiki and WordPress don't scale, and certainly aren't used internationally. Neither does Facebook. Look, there are LOTS of good reasons to avoid PHP, but suggesting that there are no business reasons to use it is just typical SWE hubris. (Which, btw, has a limited shelf life.)

We use it in my group because re-writing MediaWiki (and the 100+ custom extensions we have) would be a poor use of resources. Same story goes for our WordPress systems.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
ShuggyCoUk":14kfupg4 said:
typical SWE hubris
http://en.wikipedia.org/wiki/SWE
I'm thinking it's those damn whipper snapper's saying to use spitsticker's everywhere when the lozenge graver will do just fine in softwood.

Ahem
Sorry, just never seen that alphabetization before
Ah. It's quite common in this area (NE US). ;P
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
hanser":1nodxfxs said:
Mediawiki and WordPress don't scale, and certainly aren't used internationally.
This is more a design problem, but, no, they don't really scale unless you want to break your ass rewriting a lot of stuff to address the fact that they don't know shit about shit for a service system and are generally very poorly architected.

I feel very comfortable in saying that, for almost any public-facing web application in 2011, you support deployment across an service-oriented architecture or you probably suck. You don't have to be deployed across a SOA, but if you haven't taken into account that people will want to, I probably don't trust the rest of your code.

Neither does Facebook.
Facebook's use of PHP is primarily where, if at all, it really should be (a presentational layer). Places where important stuff matters are written in C++, Java, Python, and Erlang. Also, calling their frontend PHP seems to be becoming more and more iffy; their custom HipHop engine ends up not really being PHP and was written to address some of the serious defects in PHP. (From talking to Facebook engineers, I'd hazard a guess that a lot of them would love it if their PHP code disappeared overnight.)

Look, there are LOTS of good reasons to avoid PHP, but suggesting that there are no business reasons to use it is just typical SWE hubris. (Which, btw, has a limited shelf life.)
Man, you know I'm pretty fond of PHP (or I was, anyway), but I almost have to agree with him--regarding new projects, at least. The amount of complete fucking crap you have to do to build something from scratch doesn't just border on the ridiculous, it is full-tilt over the line and building a little cottage in Ridiculous, TN, and most modern development practices are nearly impossible in it. (Dependency injection, for example, relies on really stupid and fragile libraries like Pickle--and that's assuming you can get any dependent software to play nice with your DI container.) And technophile is 100% right about i18n in PHP: it is fucking miserable and is a callback to the bad old days if ever one existed. You end up using something like Thrift to build out your service system, and hey! Now you have autogenerated code nobody can read or understand, in different languages (because if you write your services in PHP you are dumb, dumb, dumb) on both ends of the wire.


I would not say that there's no reason to use PHP, but beginning a new, greenfield project in PHP is extremely questionable. What you get isn't great, and what you don't get is important and not having it is painful. I'm having trouble finishing the PHP book I'm writing largely for these reasons: the environment around PHP is brain-damaged and I have trouble forcing myself to use it.


I'm still waiting for a Unix-based (C#, sit down, you and I both know ASP.NET on Mono is poo), statically typed language (there's the door, Python/PHP/Ruby) that isn't stupid (fuck off, Java, goodbye, Clojure) that has web frameworks worth using (and there goes Scala out the window...). Le fucking sigh.
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
Blacken00100":184byadf said:
Neither does Facebook.
Facebook's use of PHP is primarily where, if at all, it really should be (a presentational layer). Places where important stuff matters are written in C++, Java, Python, and Erlang. Also, calling their frontend PHP seems to be becoming more and more iffy; their custom HipHop engine ends up not really being PHP and was written to address some of the serious defects in PHP. (From talking to Facebook engineers, I'd hazard a guess that a lot of them would love it if their PHP code disappeared overnight.)
I almost left that out, because I know Facebook's use of PHP isn't like the rest of the world's so it wasn't an entirely fair comparison. ;)

Look, there are LOTS of good reasons to avoid PHP, but suggesting that there are no business reasons to use it is just typical SWE hubris. (Which, btw, has a limited shelf life.)
Man, you know I'm pretty fond of PHP (or I was, anyway), but I almost have to agree with him--regarding new projects, at least.
Don't disagree at all, in fact. However there are quite a few existing codebases that are written in PHP, many of which are used in the business world, and rewriting them wouldn't be a good use of resources. But that's not what he said: 'The only "business reason" I can think of is "our programmers are too stupid to learn anything else"' -- which is a pretty ridiculous blanket statement.
 
Status
Not open for further replies.