6 ms·
> Strict-equals on objects compares the references; but regular equals compares the contents of the objects. Two objects compare equal if the contain exactly th
by eevee 14y ago
> Strict-equals on objects compares the references; but regular equals compares the contents of the objects. Two objects compare equal if the contain exactly the same fields and values. Seems pretty reasonable to me.
The line you quoted is talking about ordering, not equality.
> This is a good thing; JavaScript gets this wrong.
It IS a good thing, but it stands out when most of the language is extremely weakly-typed and even the original manual claims that separate operators for strings and numbers are confusing.
> I'm not sure if I understand this but all objects are passed-by-reference in PHP (since 5) and PHP references act appropriately when used as function parameters, etc.
So some things (objects) are passed by reference implicitly, and some (all else) are not. Yikes!
> You can declare constants in classes and namespaces with the const keyword.
Okay. Why not at top-level?
> You can cast scalars to single element arrays and objects to arrays with the same structure. Both are actually very useful.
You've practically invented a bug right there: if I write a function that can take either one value or an array of items, and you pass in a single object, I'll get a useless keyed array of its attributes.
> PHP is interpreted -- namespaces and autoloaders are PHP's module system.
What does being interpreted have to do with anything? Python and Perl are bytecode-interpreted (not positive about Ruby) and they both have rich module systems that don't require any fussing around. Heck, shell is interpreted, but zsh manages something almost like modules.
> Empty is equivalent to the not operator but will also work on undefined variables -- that's why it requires a variable.
Why does it need to look like a function when it clearly isn't one? return and echo don't.
> Useful inside of templates where matching { } is much more difficult.
In theory, but I've never seen any actual PHP code that uses them.
> Sometimes you don't care if a function succeeds; like with the unlink() function which will raise an error if the file you're trying to delete doesn't exist.
That's what exception handling is for -- unfortunately, PHP errors are an entirely separate beast from PHP exceptions.
> Not true. Debug_backtrace() will give you a stack trace in an error handler.
I said "PHP errors don't provide stack traces", and you aren't disputing that. Your own code can muck around to give you a stack trace (in most cases), yes, but the runtime doesn't do it for you.
> Assuming, of course, the programmer doesn't do anything to handle errors.
Defaults are important. I sure have a lot of people telling me it's great that PHP does web stuff out of the box -- why is it not then bad that PHP doesn't help you fix errors out of the box?
> E_STRICT (or lack of it) is for compatibility with PHP4. When enabled it will "warn you about code usage which is deprecated or which may not be future-proof." -- quote from the manual.
Yes, and that doesn't describe what it does. You can't tell what it's for, either: it's clearly not for compatibility with just PHP4, because even the PHP 5.4 release notes mention the addition of a new E_STRICT. Yet I can't be sure on what parts of the language actually ARE deprecated without reading the entire manual looking for mentions of E_STRICT.
> This author is confused why syntax errors would be parse errors but logic errors are not.
Read more carefully; the two lists are written roughly in parallel. A bogus object attribute gets a warning, but a bogus class attribute is a fatal error. (Not an exception, either, so you can't catch it with the exception handling that the OO system is supposed to be using.) A string value stored in a variable can be called, but the same string value as a literal cannot. And so on.
> This is sort of true; PHP errors and exceptions exist in different universes but it's easy to unify them and PHP even provides a built-in exception ErrorException to do so. You can turn every PHP error into an exception with 4 lines of code complete with stack traces.
Neat, though my understanding is that this still doesn't work with fatal errors, which are shockingly common.
I have the same kind of complaints about Perl's exception handling -- it's entirely possible to hack it into something more useful, but why on Earth should I have to mess around just to make something as fundamental as errors be developer-friendly?
> PHP supports both procedural and OO programming styles -- this is not a bad thing.
Exception handling isn't inherently OO. Perl has its own flavor of try/catch that requires zero objects whatsoever.
> PHP is reference counted with a cycle-detecting GC. That would not leak memory.
I believe it used to, but I removed this due to the short window during which it was a bug. I see this list of counter-arguments hasn't been updated in a while.
> This is true, but it's an ongoing discussion on how to correctly handle scalar type hints. For all the discussion about how PHP isn't designed the author takes issue with the thing they're taking their time on.
My issue isn't that they're taking their time, but that they implement half of a feature and then decide to sit down and think about the other half (while now constrained by whatever hack job they've already done).
> Because of the dynamic abilities of PHP, there is simply no way for the interpreter to ever figure out the variable to close over.
Every other dynamic language ever sure seems to be able to get this right.
> C++ does it. $obj::foo doesn't make any sense, if you're accessing class attributes then you use the class name Class::foo.
Then why not use Class->foo? Why does this need two operators? $obj::foo is perfectly reasonable if I want the foo attribute of whatever class $obj is; that's half the reason I ever use class attributes.
> This is personal taste not a valid critique.
Yes, which is why I said it's personal taste. Regardless, it's still wildly inconsistent with the rest of the language and poorly bolted on.
> That is, in fact, the point. PHP is supposed to be a thin scripting language layer over C. It's expanded beyond that. Many of the poor naming conventions are not because of PHP but rather are the exact API of the underlying C library.
How many people using PHP today came from C, exactly?
> Both the C API and PHP have both these functions for backwards compatibility reasons.
No. The C API has two functions because one takes only a value to escape, and the other takes both a value and a connection pointer. Both functions in PHP can be called with merely a value, and the "real" one will use the current global connection. Zend could have merely switched the old escape function to have the new behavior, and all existing code would have been instantly fixed, not broken.
> Most of these are provided by frameworks just as they are in Python, Ruby, C#, etc.
PHP is praised for its web features, but is missing a whole pile of functionality instrumental for actually writing nontrivial web applications. Either judge PHP only by the core language, or judge everything else by what you get with frameworks.
- wvenable 14y ago> It IS a good thing, but it stands out when most of the language is extremely weakly-typed You only need distinct operators if your language is weakly typed. If you language is strongly typed like Python, Java, or C# then there is never any conflict between addition and concatenation. VB/VB.NET is also weakly typed and has separate operators. > So some things (objects) are passed by reference implicitly, and some (all else) are not. Yikes! Yes, like most ever other language in existence. You know, Java, C#, Python, etc. > Okay. Why not at top-level? Because all code should be contained within a namespace going forward. Constants should not be defined in the top-level. > if I write a function that can take either one value or an array of items, and you pass in a single object, I'll get a useless keyed array of its attributes. No, it doesn't work that way. You have to explicitly cast. If you use an array type-hint you can only pass an array. > Python and Perl are bytecode-interpreted (not positive about Ruby) and they both have rich module systems that don't require any fussing around. PHP is also bytecode-interpreted. I'm not really sure what point you're trying to make. It's super easy to integrate code from different libraries with namespaces and autoloading. > Why does it need to look like a function when it clearly isn't one? return and echo don't. Because it's used an expression not a statement like return and echo. The fact that is or is not a function is insignificant; you use it the same way. > In theory, but I've never seen any actual PHP code that uses them. In templates you see it all the time. > That's what exception handling is for -- unfortunately, PHP errors are an entirely separate beast from PHP exceptions. If you convert all errors to exceptions, you could catch it. It's just an additional feature. If you handle your own errors, you can even ignore the error suppression operator if you choose. > I said "PHP errors don't provide stack traces", and you aren't disputing that... but the runtime doesn't do it for you. Oh, you're saying if you don't provide any of your own error handling and let it spill out the terminal -- yes, you're right -- no stack trace by default. Not that you should be doing that. If you really want that though, it can be provided by the XDebug extension. > it's clearly not for compatibility with just PHP4 The lack of E_STRICT helps you run PHP4 code on PHP5. That's why it's not included in E_ALL. For example, I have an application that runs unmodified on PHP4 and PHP5. > Yet I can't be sure on what parts of the language actually ARE deprecated without reading the entire manual looking for mentions of E_STRICT. Turn on E_STRICT and it'll tell you. > A bogus object attribute gets a warning, but a bogus class attribute is a fatal error. Yes, one is defined and one is not. > A string value stored in a variable can be called, but the same string value as a literal cannot. Calling a string literal is pointless! 'test'() is test()! > Neat, though my understanding is that this still doesn't work with fatal errors, which are shockingly common. Fatal errors are not that common but I won't argue the point too heavily because they are a bitch. PHP developers are trying to reduce the number of fatal errors. Most IDE's will notify you of fatal error as you type. > but that they implement half of a feature and then decide to sit down and think about the other half (while now constrained by whatever hack job they've already done). There's nothing controversial or difficult about object type hinting. Also since PHP is meant to be typeless there is some discussion over whether scalar type hints are even necessary. Giving you something you can use right now is not a bad thing. > Then why not use Class->foo? Why does this need two operators? I suspect historical reasons. They really did do very different things in PHP3/PHP4. > Regardless, it's still wildly inconsistent with the rest of the language and poorly bolted on. How so? It's PHP object system, there is nothing for it to be inconsistent with in the rest of the language. > How many people using PHP today came from C, exactly? It's not about whether they came from C -- it's the fact that PHP quickly implemented access to a huge library of existing C libraries (and tracked their changes). This was a huge deal back when PHP was younger. > Zend could have merely switched the old escape function to have the new behavior, and all existing code would have been instantly fixed, not broken. If you've ever complained about security in PHP, you need to give that up right now. Because you just gave everyone a false sense of security. > Either judge PHP only by the core language, or judge everything else by what you get with frameworks. Wait, why? That's ridiculous.