www.webdeveloper.com
Page 3 of 14 FirstFirst 1234513 ... LastLast
Results 31 to 45 of 198

Thread: My questions thread.

  1. #31
    Join Date
    Jan 2009
    Posts
    3,346
    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.

  2. #32
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    Quote Originally Posted by evenstar7139 View Post
    ...as many as 100 columns....
    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

    eBookworm.us

  3. #33
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Quote Originally Posted by NogDog View Post
    EXPLAIN can be your friend.
    Hmm, too bad I don't have that database anymore Oh well.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  4. #34
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    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.

  5. #35
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    Quote Originally Posted by evenstar7139 View Post
    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

    eBookworm.us

  6. #36
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Hey guys. I'm struggling with understanding what making a call is. Can you tell me which of the following situations constitutes calling?

    #1
    PHP Code:
    require('somefile.php'); 

    #2
    PHP Code:
    $person = new Person(); 

    #3
    PHP Code:
    $person->getName(); 

    #4
    PHP Code:
    $firstName 'Bob';
    print 
    $firstName

    #5
    PHP Code:
    mysql_query("SELECT name FROM people"); 
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  7. #37
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    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

    eBookworm.us

  8. #38
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    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.

  9. #39
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    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

    eBookworm.us

  10. #40
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Is using DOCUMENT_ROOT in an include path insecure? If so, why?

    PHP Code:
    require_once($_SERVER['DOCUMENT_ROOT'].'/foldername/filename.php'); 
    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.

  11. #41
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    I do it all the time, so hopefully it's okay.

    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

    eBookworm.us

  12. #42
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    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.

  13. #43
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,325
    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

    eBookworm.us

  14. #44
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    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.

  15. #45
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by evenstar7139 View Post
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles