Hmm, how about quoting strings in single quotes verses double quotes? I was always told to do this. I was told my scripts would parse faster or something. I'm guessing it doesn't help performance much? Do PHP programmers just do this because it's easy?
Back in the day there was a minor performance difference between single quotes and double quotes. The actual performance issue these days is minimal it really doesn't matter and can be up to preference.
While it might not necessarily be wrong, this raises a red flag for me -- especially if you ever were doing "SELECT * FROM..." that table and retrieving all 100 columns of data with every matching row.
However, without knowing the details, there's no way to say for sure -- but EXPLAIN can be your friend.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Hey guys, I was reading about callbacks and anonymous functions and I can't see the significance of them. All they are is functions with no name and placed in variables, right? What is the purpose of this?
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
Hey guys, I was reading about callbacks and anonymous functions and I can't see the significance of them. All they are is functions with no name and placed in variables, right? What is the purpose of this?
Anonymous functions are useful in cases where you only need a function (such as a callback function for a usort() call) in one specific place, so there is no need to create a named function. Assigning it to a variable allows you to decide at run-time which function to use, such as using an if/else or switch() to choose which function to send to another function as one of its parameters. (I've never done the latter, but have often used anonymous functions in usort() calls and other functions that use callbacks.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
I don't know that "call" is precisely defined anywhere, but I would say that 1 and 5 are function calls, 3 is a method call, 4 is a variable assignment followed by a function call, and 2 is an object instantiation (being assigned to a variable).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thanks. Anyway, different question now: If I am starting a new project from scratch, and the place where the application will run has the newest version of PHP, should I go ahead and use features that are only available in the newest PHP version (5.4 as of this writing)? What if the person whom I made the application for switches web hosts and that host only has an older version, like 5.3. Is it just too bad for them and not my problem?
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
That should be part of the requirements discovery/analysis phase. There is no single correct answer: it depends on the needs of the client, and you should make sure there is a mutual agreement as to what the delivered product will require in terms of a production environment.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
If you're wondering why I'm asking, I'm trying to make is so I can use relative file paths from anywhere in my file system. This is so the application can be placed on any site and I don't have to go through and change all the paths of included files.
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
Seriously, there should be no problem, as long as you are not using unsanitized external inputs in conjunction with it, e.g.:
PHP Code:
$_SERVER['DOCUMENT_ROOT'].'/'.$_GET['path'];
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Well, that's all good to know. If you haven't had any trouble with DOCUMENT_ROOT then I'm gonna go ahead and use it. Compared to other methods that make it so the includes in an application aren't tied to a particular file system, this method seems easiest.
- - -
Anyway, I'm here right now because I'm wondering if I understand object type correctly. An object's type is that of the highest class in the heirachy of classes that it came from, right?
For instance, if I had, I don't know, how about a Dog class. Let's say Terrier_Breeds inherits from that and then American_Staffordshire_Terrier inherits from Terrier_Breeds. An object created from American_Staffordshire_Terrier would be of the Dog type, yes?
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
American_Staffordshire_Terrier would be each of the following types:
a. American_Staffordshire_Terrier,
b. Terrier_Breeds, and
c. Dog
So, you could type-hint for any of those three, and the AST class would be accepted as such, while an object of type Dog would only only pass as a Dog type.
To add an additional layer:
PHP Code:
class Dog
{
}
interface iBreedGroup
{
}
class HerdingGroup extends Dog implements iBreedGroup
{
}
interface iBreed
{
}
class AustralianCattleDog extends HerdingGroup implements iBreed
{
}
An object of AustralianCattleDog would be accepted as a parameter for any of these type-hints: Dog, HerdingGroup, AustralianCattleDog, iBreedGroup, or iBreed.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How does a PHP developer protect them self legally? When they make a web application for a client, how do they keep from being liable in the event it is hacked?
And woohoo 200th post
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
How does a PHP developer protect them self legally? When they make a web application for a client, how do they keep from being liable in the event it is hacked?
And woohoo 200th post
I usually make sure to have documented that all liability and ownership of work is transferred to the requesting party as I only work code-for-hire for personal projects. In a business environment usually some/most liability will be mitigated through the hiring organization as they will also usually have a code-for-hire clause in employment contracts.
Bookmarks