Domain: php.net
Stories and comments across the archive that link to php.net.
Comments · 1,658
-
Re:We need a really big lawsuit against Microsoft
All incoming e-mail is reformatted. Attachments are converted to
A utility I use on my server's admin accounts is a simple ~10 line PHP script run by the input filter via Xmail. It just runs strip_tags() on the body text of the email after which I drop non-image attachments. This basically makes sure all of my admin mail is text at SMTP. I originally did it because I was using a text-only reader for that mail at one point, but I've never thought of it as a security measure until you brought up your points. I wonder what my users would think of that... .odf or .png, as appropriate. Stuff that can't be converted is dropped. HTML is parsed, checked for syntax, and Javascript dropped. -
Re:The "Oh-Sh*t" face...
> Perl's DBI, whose docs tell you to ALWAYS write SQL like:
> $sth = $dbh->preprare('SELECT foo,bar FROM baz WHERE something=? AND another = ?')
> $sth->execute(q{''Some\ things"'}, 10);
PDO does exactly this:
$dbh = new PDO("connstring");
$sth = $dbh->prepare('SELECT foo,bar FROM baz WHERE something=? AND another = ?');
$sth->execute(array($something, $another));
Check it out http://www.php.net/pdo -
Re:Non-alphanumerics at last!
Just to clarify my original point... try searching for '@' in the PHP online manual, you'll get no matches
-
Re:DB Wrapper?
You should probably be using this API, particularly the prepare statement/execute functions of it.
-
Re:Better APIs
PHP has supported parameter substitution for years. Quit spreading this myth.
The problem is simply that none of the standard "how to program with PHP" introductory texts mention it, but jump straight into low-level MySQL-specific APIs that shouldn't ever be used directly, IMO. -
Re:Turn Key solutions broken?Let's face it, PHP hasn't had a standard database API for quite a long time (I guess there's PDO now). The most common database that PHP is used with is MySQL, which did not have bind parameters for quite a long time, so PHP programmers resort to mysql_real_escape_string or before that mysql_escape_string and then concatenating the query and the parameters while better databases have supported bind parameters since PHP 3. And even if the database API does not natively have separate parsing and binding stages, at least it would make sense to emulate them, because if the database API later gains the ability to bind parameters / send parameters separately from the statement, the users don't have to change their code. If mysql_query was used like this:
mysql_query($db, "select * from products where (color = ?) and (price < ?)", $color, $maxprice);
Then no-one would complain about escaping statements being "hard". Instead we have things like gpc_magic_quotes instead... -
Re:Turn Key solutions broken?Let's face it, PHP hasn't had a standard database API for quite a long time (I guess there's PDO now). The most common database that PHP is used with is MySQL, which did not have bind parameters for quite a long time, so PHP programmers resort to mysql_real_escape_string or before that mysql_escape_string and then concatenating the query and the parameters while better databases have supported bind parameters since PHP 3. And even if the database API does not natively have separate parsing and binding stages, at least it would make sense to emulate them, because if the database API later gains the ability to bind parameters / send parameters separately from the statement, the users don't have to change their code. If mysql_query was used like this:
mysql_query($db, "select * from products where (color = ?) and (price < ?)", $color, $maxprice);
Then no-one would complain about escaping statements being "hard". Instead we have things like gpc_magic_quotes instead... -
Re:Turn Key solutions broken?Let's face it, PHP hasn't had a standard database API for quite a long time (I guess there's PDO now). The most common database that PHP is used with is MySQL, which did not have bind parameters for quite a long time, so PHP programmers resort to mysql_real_escape_string or before that mysql_escape_string and then concatenating the query and the parameters while better databases have supported bind parameters since PHP 3. And even if the database API does not natively have separate parsing and binding stages, at least it would make sense to emulate them, because if the database API later gains the ability to bind parameters / send parameters separately from the statement, the users don't have to change their code. If mysql_query was used like this:
mysql_query($db, "select * from products where (color = ?) and (price < ?)", $color, $maxprice);
Then no-one would complain about escaping statements being "hard". Instead we have things like gpc_magic_quotes instead... -
Re:Turn Key solutions broken?Let's face it, PHP hasn't had a standard database API for quite a long time (I guess there's PDO now). The most common database that PHP is used with is MySQL, which did not have bind parameters for quite a long time, so PHP programmers resort to mysql_real_escape_string or before that mysql_escape_string and then concatenating the query and the parameters while better databases have supported bind parameters since PHP 3. And even if the database API does not natively have separate parsing and binding stages, at least it would make sense to emulate them, because if the database API later gains the ability to bind parameters / send parameters separately from the statement, the users don't have to change their code. If mysql_query was used like this:
mysql_query($db, "select * from products where (color = ?) and (price < ?)", $color, $maxprice);
Then no-one would complain about escaping statements being "hard". Instead we have things like gpc_magic_quotes instead... -
Re:The "Oh-Sh*t" face...
You're exactly right, PHP hasn't had anything that does prepared statements for several years
-
Re:Return of the Flat File
-
Re:Non-alphanumerics at last!
From the PHP manual entry on including files (my example is too simple, and in fact this is where it came from):
My experience is you can use an if-statement to verify if the script was included (I havn't tested this on remote includes, there might be non-standard-404 pages that makes it impossible to verify you got the right page)
Example: // ignore the notice and evaluate the return value of the script, if any.
if(@include(dirname(__FILE__)."/foo.php"))
echo "foo.php included";
else
echo "failed to include foo.php";So if you need to see if the include might have worked (and not forgetting cases where testing if a file exists doesn't mean it can be included) then this type of construct might be useful. I use it to try to include a specific header file based on URL attributes, otherwise include a generic replacement file.
You are of course correct in saying that code should try not to be lazy, and ignoring errors is a Bad Thing. Sometimes you can find use for that, and in my case above I hope this is OK (feel free to post an alternative, I'd be happy to include it in my code).
You are also correct that parsing was the wrong term. The syntax is parsed, and then the execution begins which can throw errors. So it's not a question of parsing. My apologies.
-
Re:top 5php.net/mysqli has prepared statements, or you can use PEAR's MDB2:
* Prepare/execute (bind) named and unnamed placeholder emulation
-
Re:top 5php.net/mysqli has prepared statements, or you can use PEAR's MDB2:
* Prepare/execute (bind) named and unnamed placeholder emulation
-
Re:There really is no excuse for this.
And you can use it with PHP to boot.
-
Re:Rather incomplete quote
Prefixing every variable with a $ doesn't seem to serve any real purpose. Ok, so I can have a variable called $variable and a function called "function". I could do that anyway. It means you don't have to define variables to use them -- same with Ruby, except Ruby doesn't use prefixes. Perl uses prefixes, but it also uses them for interpolation in strings -- I don't think PHP can do that. Ruby manages that interpolation without prefixing variables except when they're in a string.
I hate PHP too, but it can interpolate variables in strings...
-
Re:and php is not broken?
Wow, a link that points to nothing at all, and a lack of an explanation. Gee, an introductory tutorial isn't focussed on security. Maybe that's because they're teaching the language first?
Fair enough, here is the explanation:From the Dealing with forms section in the tutorial:
Hi <?php echo $_POST['name']; ?>.
You are <?php echo $_POST['age']; ?> years old.They are teaching to just echo the variable that the user might enter. A newbie will follow this pattern in future projects since that is what he is taught. Asume for a second that the name can be entered by any person, and a site's administrator reads this on a page with code looking like the above.
If a person enters "John doe" for the name, no problem, but if an attacker enters:
<script>//some trivial javascript to send all cookies to attacker's site</script>
presto, the attacker can easily steal the session id and maybe something else from the site's administrator. What the tutorial should say instead, if it was not broken according to Rasmus definition is:Hi <?php echo htmlentities($_POST['name']); ?>.
either that, or filter out the variable on input (htmlentities is cleaner).
You are <?php echo htmlentities($_POST['age']); ?> years old.You can read up a lot more about XSS in wikipedia. The tutorial is vulnerable to what they call type 2.
-
Re:There ARE other scriping languages besides PHP
PHP takes care to keep things consistent
You have no idea what you're talking about, do you?
Take a look at the string functions. We have str_replace and strtr. htmlentities and html_entity_decode. Inconsistent underscores. bin2hex and strtolower, they can't decide whether to use 2 or to. Why do some functions begin with "str" and others don't? I'm not using C.
Oh, and I keep getting the arguments mixed up. explode and implode seem backwards. strstr is (haystack, needle); preg_match is (needle, haystack). Why?
May I go on? I can go on.
PHP is the opposite of consistent. Whenever I program PHP, I have to keep a window with the docs open, because I keep having to look up if it's stripslashes or strip_slashes or whatever. Terrible. -
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Zend's ZActiveRecord Boondoggle
The creators of PHP are morons, and their support company Zend is dishonest and incompetent. The ZActiveRecord boondoggle demonstrates exactly what I mean: They can't program their way out of a paper bag, an don't even understand the limitations of the very language that they haphazardly "designed".
It makes me laugh that Lerdorf would slam Postgres, because the PHP designers have no understanding of object oriented programming or databases: instead they invent half baked cargo-cult designs, which are naive reactions to other systems they don't understand: they try to ape their surface features without understanding the reasons behind the way they're designed.
PHP references were thrown in as a band-aid to work around the horrible design flaw that arrays and objects were foolishly DEEP COPIED by default. If you pass or return an array from function to function, its contents are DEEP COPIED, which is EXTREMELY inefficient and leads to all kinds of horrible bugs because it's the last thing a sane programmer would expect. So instead of fixing the design flaw in PHP, they add "references" that LOOK and SOUND like C++ references, but actually are completely different, again misleading programmers into thinking they understand what's going on, but working totally differently than a sane person would expect. PHP references are actually half baked symbol table references. The sloppy implementation caused many bugs that CORE DUMP PHP! PHP references were so poorly thought out and badly designed, that there were many edge conditions that they hadn't considered, that simply didn't work together, caused memory leaks and core dumps, and had useless and confusing semantics: callers passing references, functions declaring that they take references, functions returning references, etc. Compare that to C++'s simple and consistent definition of references in term of pointers. The only way to make a PHP reference to an object is to put it in a variable -- you can't make a reference to a field of an object or the return value of a function without storing it in a temporary variable -- totally unlike C++, and totally stupid.
PHP's object oriented programming system is a half-baked imitation of C++'s object model, haphazardly designed by charlitans who had no clue about the fundamentals of object oriented programming, elegant language design or efficient implementation. First of all, if you're going to try to imitate an existing design without understanding it, then for god's sake, at least imitate a language whose object system doesn't suck, and a language that has similar semantics to the language you're trying to kludge. C++ is a static compiled language, and its object system deeply reflects that fact. (That is to say, there's very little reflection beyond RTTI, because the compiler throws all the interesting stuff away! And C++'s oop design had to make many horrible compromises because the C++ object system was designed to map directly into C semantics [since the original C++ compiler compiled C++ into C.]) Most of those C++ design decisions make absolutely no sense for a dynamic interpreted language like PHP. (Many of them made very little sense for C++ itself, but even less sense in the context off PHP.)
One prime example of how PHP screwed up its object system, is that they blew it on static methods, in a way that makes it impossible to properly implement an ActiveRecord-like ORM (among other us
-
Re:Rather incomplete quote
have been doing this stuff a long time and have been slammed on
/. countless times, but please, slam me for things I actually said or did.Sure thing. Did you say this?
Part of the reason Lerdorf considers the Web "broken" is that it is inherently insecure for a variety of reasons. One of those reasons sits at the feet of developers. "You don't know that you have to filter user input," Lerdorf exclaimed.
If you don't like insecurity due to poor input handling, why did you design your language to encourage it? magic-quotes-gpc is the worst language feature I have ever seen. It manipulates one particular set of inputs to make them conform to one set of output which doesn't always apply but is always a bad idea. People should be using bind variables supplied by the database library, not quoting according to MySQL x.x's rules and then sticking things directly into their statements. This is like a giant neon sign called "Security" pointing in the opposite direction from the real thing.
In contrast, Perl has taint mode, a feature you'd do well to emulate. It actually tracks a flag on each variable seeing if it came, directly or indirectly, from untrusted input. If so, it must be untainted before being used in any of a number of security-related situations. It's smart enough to avoid requiring any way of doing so which is probably inappropriate. It just flags things which are almost certainly wrong. Actual thought needs to go into correcting them, and as users learn the situations taint mode complains about, they trip it less and less often. Correct taint-mode code runs the same with it off, which makes it much superior to magic-quotes-gpc.
-
Re:There ARE other scriping languages besides PHPNo, this myth comes from the PHP manual, which says
PHP succeeds an older product, named PHP/FI. PHP/FI was created by Rasmus Lerdorf in 1995, initially as a simple set of Perl scripts for tracking accesses to his online resume.
-
and php is not broken?This guy has some b*lls, I have had the displeasure of using php for a couple of years.
Here is a good summary of some of my complaints. But wait, there is more:
As a programming language, php is extremelly poor. Off the top of my head:
- Very poor object oriented language. Not everything is an object, no multiple inheritance, use destructors and you get segfaults, etc... They improved a lot with v5 but still.
- No higher order functions. As opposed to Python, Perl, Ruby, and hundred others.
- No closures
- No operator overloading
- No aspect oriented constructs, metaclasses, decorators, nada
and then there is the issue of all the weird behaviours it has
-
consider this code:
$x = NULL;
What do you expect to happen? well, an exception obviously. NOT, php guesses you really meant to create an object, assign it to $x and that the object has an attribute a. It does not even issue a warning in the logs. Makes it really fun to debug some programs.
$x->a = 10; - References are just weird. And they are so different from version 4.0 to version 5.0 that it made it imposible to upgrade for an existing project
- arrays are passed by value, but objects are passed by reference, WTF?
- variables are case sensitive, but methods are not. WTF?
The language itself seems to promote what Rasmus calls "broken" code. Magic quotes are just an open invitation for SQL Injection, and XSS vulnerabilities.
For fck sake, the php tutorial teaches how to write cross site script vulnerable code which is what Rasmus is complaining about. WTF?????
P.S. Forgive my grammar, english is my second language
-
Re:This is a big deal
Also in PHP > 5.2
-
Re:Ok?
Don't forget about the fect that none of this would be possible, as an unprivelaged user, without [warning: PDF!] Session Fixation which is easily avoided by using session_regenrate_id in PHP when the user logs in. Those 'stored session IDs' would all bcome expired upon login, and contain no important information.
Any serious PHP developer does this. Also, I wouldn't peronally choose to run or develop my software on PHP4. 5 is so much better. After having spent the past year developing PHP5, PHP4 is just... ew.
And Smarty makes HTML escaping user input easy and fun! -
Some simple fixes would be sufficientAs short summary, what every (PHP) developer should do is:
- limit the session to the IP-address of the visiting user.
- use htmlentities() on all outputted HTML
- secure file uploads to avoid uploading PHP code
- use mysql_real_escape_string() on all database input, or better: the variable binding feature of PEAR::DB
- disable register_globals, use $_GET, $_POST and $_COOKIE instead.
- Use preg_replace( '/[^a-zA-Z0-9\-_]', '', $input ) on all input used in file names.
Things like require_once("files/" + $input + ".html") actually read php files when it's called as ?input=file.php%00
-
Some simple fixes would be sufficientAs short summary, what every (PHP) developer should do is:
- limit the session to the IP-address of the visiting user.
- use htmlentities() on all outputted HTML
- secure file uploads to avoid uploading PHP code
- use mysql_real_escape_string() on all database input, or better: the variable binding feature of PEAR::DB
- disable register_globals, use $_GET, $_POST and $_COOKIE instead.
- Use preg_replace( '/[^a-zA-Z0-9\-_]', '', $input ) on all input used in file names.
Things like require_once("files/" + $input + ".html") actually read php files when it's called as ?input=file.php%00
-
Baroque doesn't begin to describe itThe PHP Function List gives 4,834 functions in the main namespace. The problem is that rather than start with a small set of orthogonal primitives and build upon them, they've added a new function for each and every possible operation anyone would ever want to perform.
For example, PHP has a special function to see if a given key is in an array:
array_key_exists('key', myarray)
In Python, you'd use the standard syntax for determining if a value is present in any list-like object
'key' in myarray
If you ever change myarray into a different kind of object, like a list, set, or database-backed persistent store, that exact same expression still works. That is, it's not anything special for arrays, but part of the general structure of the language.
And that's why I can't stand PHP. While it may work perfectly, you have to learn an enormous amount about the language before you can really become proficient. I'd rather learn something with a small syntax that I can master quickly and build upon. I realize that comes down to personal preference, but I think that's the majority opinion here.
Sure, php.net is an excellent resource. I contend that it has to be or no one would ever be able to use the language. It's simply too large to memorize.
-
not another
i hate when people post about php books in slashdot.
it's soo damn overrated.
all these php books.
php.net -
php-embedThe book sounds interesting. There's also an often-overlooked capability of PHP: the ability to use php-embed to run embedded PHP within a C/C++ app. For example, our company created an HL7 accelerator--we chose PHP as the embedded language in our product--by which users can more easily create custom data transformations.
The reason? PHP is easy to use, loosely-typed (which happened to be an advantage in this case), fast, and of course the license works. It was a great decision.
PHP-embed is basically just a TSRMLS function wrapper. It's pretty straightforward; for example, zval integration is easy as pie, as I recall, something like:
zval *zarray;
MAKE_STD_ZVAL(zarray); ...
if ( array_init(zarray) == FAILURE ) { // ... something wrong
}
add_assoc_string(zarray, str_name, str_val, 1);
ZEND_SET_SYMBOL(&EG(symtab), tokenlevel, zarray); -
Re:From IRC, the reason:
Not got the logs of the conversation, but this would seem to indicate the truth of the conversation.
-
Re:From IRC, the reason:This seems confirmed (or at least corroborated) here:
http://news.php.net/php.internals/25044From: Andrei Zmievski Date: Fri Jul 28 13:15:17 2006
Subject: Re: Why did Jani quit?
References: 1 Groups: php.internals
He was ranting on IRC about Israel bombing a UN post in Lebanon. He
used to do the same job for UN, by the way.
From #php.pecl:
Jul 27 17:16:21 I will also quit this project. As long as
it's backed by some Israel company, I don't want to have anything to
do with it.
-Andrei -
Independant, trustworthy corroboration:
A partial quote of the log from a trusted member of the PHP community with a timestamp not included in my quote.
http://news.php.net/php.internals/25044
I hope this settles any speculation about who is or is not a Mossad agent fabricating stories to destroy the internet. -
No one seems to care
So far it's Slashdot 59 - php.internals 0. Check the php.internals group.. no one seems to care, or at least no one feels like it's appropriate to respond. You'd think there would be more public outcry in the PHP community?
-
Re:How difficult is it.
PHP's mysql_real_escape_string() won't do squat.
According to the documentation:
mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.
This does nothing against the attack I described. If you called mysql_real_escape_string() on the code I gave you, you will still end up with an SQL string of:
"SELECT * FROM MyTable WHERE MyID = 1 OR 1 = 1"
As for your other suggestion about forcing everything to string in the database ...
I am reaching the opinion that most people who work with MySQL seriously need to spend some time with a real database. It seems to retard understanding of basic database concepts. -
Re:The problem with the alternatives to PHP
I'm not saying it should be used for desktop gui apps though
why not? -
Lack of PHP Security in 5 sentences, Not 500 Pages
I think you just showed us why you need more than five sentences to describe PHP security.
For one thing, you're not protecting yourself from URL-encoded strings.
And since PHP doesn't yet support bind-variables (prepared statements) natively, looking at PEAR::DB is a good idea; it saves you the hassle of quoting and whatnot.
You're also not dealing with the problem of XSS, since you've failed to deal with output to screen.
You are, in fact, not dealing with anything that's not related to MySQL. -
PEAR::Auth & PEAR::LiveUser
There are several libraries from the PEAR project
Try this : http://pear.php.net/packages.php?catpid=1&catname= Authentication -
Re:The problem with the alternatives to PHP
Check out Smarty. MVC in PHP is something that, like many other C-derivative languages, is not forced. The writer has the option to ignore MVC completely. Just follow any old guide to the generics of MVC if you don't want to use a template engine. It really isn't that hard...
-
Re:User/role management
When will people learn to check the PEAR before asking for PHP functionality?
http://pear.php.net/package/LiveUser supports users from multiple sources (at the same time), group permissions and per-user-permissions. -
Re:Hard for Devs?
PHP does, stop spreading FUD.