SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Saj's Avatar
    Join Date
    May 2003
    Location
    USA
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function Names in Classes

    I've noticed that you can use functions with the same names as standard PHP functions in classes, probably because you aren't calling the PHP function directly.

    I wanted to know whether it was a good idea, though it works, to use the same function names. I'm working on a simplified database class, and was wondering if I could name the functions mysql_connect(), mysql_query(), etc.

    Thanks in advance.
    - Saj

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I imagine you probably could, however, it would kind of eliminate the point of using a class to an extent. You wouldn't be able to be as portable using mysql_ as a prepend to your functions, since that implies mysql. It would be best to just name it connect. You could then plug and play your database if you wanted.

    Just something you may want to think about.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to write a SQL abstraction class, why not use some name that is even more general, like $dbObj->query($sql). The naming you mentioned might create confusion when reading code, but it will be interpreted correctly by PHP (given you call it correctly, $obj->func() and not just func() )
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


Bookmarks

Posting Permissions

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