 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Stoimen Popov's Blog: PHP Don't Call the Destructor Explicitly
by Chris Cornutt November 16, 2011 @ 11:56:43
In this new post to his blog Stoimen Popov talks about calling the "destructor" method of an object and why doing it directly could lead to some issues - like not actually destroying the object before the script ends.
At the end of the script the interpreter frees the memory. Actually every object has a built-in destructor, just like it has built-in constructor. So even we don't define it explicitly, the object has its destructor. Usually this destructor is executed at the end of the script, or whenever the object isn't needed anymore. This can happen, for instance, at the end of a function body. Now if we call the destructor explicitly, which as I said I've seen many times, here's what happen. As you can see calling the destructor explicitly doesn't destroy the object. So the question is...how to destroy an object before the script stops?
He points out that one way to "destroy" an object is to null it out and remove the structure from memory. This is tricky, though, because a clone of the object will still exist in memory, just not the original.
voice your opinion now!
destructor call directly null clone object
Dan Horrigan's Blog: The Value of Null
by Chris Cornutt April 19, 2011 @ 10:51:18
Dan Horrigan has a new post to his blog talking about the value of null - a quick summary about when and where null should be used. Null's a value too, after all...
Let me start off by saying this article is about PHP and PHP alone. Other languages handle this sort of thing differently (and better). In PHP many people (and a few frameworks) return FALSE from methods when the requested value does not exist. However, I am here to tell you that if you do this, you are doing it wrong. Plain and Simple.
In his opinion, "false" is definitely not the same thing as "null" because "null" is technically the absence of a value, not a "not true" value like "false" is. He illustrates with a simple use case of a class that has methods returning various values.
voice your opinion now!
value null opinion false return
Jani Hartikainen's Blog: What is a null object, and when are they useful?
by Chris Cornutt September 14, 2009 @ 12:46:10
In this latest post to his blog Jani Hartikainen looks at creating "null objects" for your applications - a simple tool that lets you replace multiple evaluation checks with a simple object.
How many times have you written code, which checks if a value is null, and then displays something special because of that? Have you written the very same check in more than one place in your code? A null object is an elegant solution to this.
His example shows how to replace a standard User class to grab the user's name with an anonymous user that extends it to return the string "Anonymous User" instead. By creating an intermediate class like this, you can simple call a "getName" and know that there will be some sort of value as the result.
voice your opinion now!
null object anonymous tutorial
Davey Shafik's Blog: Return Values
by Chris Cornutt February 04, 2009 @ 11:14:28
Davey Shafik has taken a look at return values and keeping them standard when handing them back from the results of a database query.
In #phpc we recently had a discussion about function return values; specifically from database queries. I'm going to go on a (admittedly, rather sturdy looking) limb and say this applies to pretty much any function that returns from a data resource, not just a database .
His personal preference is to return the results data if there's matching information but to return a false value if there is an error/not results were found. He includes a snippet of example code to show the structure he's talking about. Some of the comments on the post mention things like exception handling, other similar methods other developers use and the use of nulls.
voice your opinion now!
return value array false null exception comment
Brian Moon's Blog: Null vs. isset()
by Chris Cornutt January 29, 2009 @ 09:34:59
In this new post to his blog, Brian Moon compares two things that, on the outside, might seem a lot alike but do have their differences under the hood - a null value and the isset function.
I am working with a newcomer to PHP and he asked me about setting a variable to null and how to check that. He had found some example or information that showed that setting a varaible equal to null would unset the variable. So, he was unclear if he could then reliably check if the variable was equal to null. Having avoided null like the plague in my years of PHP, I was not sure. So, I mocked up a quick script to see what the states of a variable are in relation to null.
His test verified that a variable, set equal to null will be found to be equal to null, will be set (isset) and will be found empty by PHP's empty
voice your opinion now!
null value variable compare isset empty
DevShed: Null and Empty Strings
by Chris Cornutt December 03, 2008 @ 11:16:51
On DevShed today, there's a new tutorial posted looking at two things that can cause headaches for PHP developers (especially when evaluating and comparing values) - nulls and empty strings.
Anyone who has programmed for any length of time has encountered the concepts of null and empty strings. They are not the same, and confusing the two can cause some serious problems. This article deals with these concepts in the context of PHP and MySQL.
They start with a bit of a quiz before getting into how to handle them correctly - making null "safe" and working with it correctly in a MySQL context. SQL statements and table structures are included for their examples.
voice your opinion now!
null empty string tutorial mysql handle safe
Clay Loveless' Blog: PHP and JSON Cut #987
by Chris Cornutt March 01, 2007 @ 08:43:00
In a new post today, Clay Loveless talks about some issues he's been having with PHP and JSON, specifically with the JSON encoding method in PHP 5.2.1.
As of PHP 5.2.1, json_decode() no longer follows the published standards for JSON-encoded texts. Why not? For no reason other than the convenience of those ignorant of JSON standards.
His complaint stems from the results of a vat_dump statement - prior to this version it would give a NULL, but now it returns a "bool(true)" value back, resulting in some breakage of previous scripts. He spends the rest of the post explaining his voyage through the JSON world and how things are supposed to behave. He also digs a little deeper into the var_dump issue and why he thinks it's such a bad thing.
voice your opinion now!
json vardump null true strict adhere extension standard json vardump null true strict adhere extension standard
|
Community Events
Don't see your event here? Let us know!
|