Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Static functions in PHP?

tvientitvienti Posts: 230Member
Hey,

I think I missed something in my PHP journey. Are there no static object methods in PHP (prior to 5, which I haven't even looked into yet)? I'm trying to wrap objects around my DB tables and giving each a select($id) method that is called on the class level and returns an instance... IE:

[code]$myAcct = Accounts->Select($id);[/code]

Is that not possible? Is there a workaround that's not more complicated than it's worth? I'm trying to avoid a DB wrapper class that's nothing but a series of variously named functions like selectAccount($id), selectUser($id), ...

Any help would be appreciated.

T

Comments

  • friendkeyfriendkey Posts: 3Member
    : Hey,
    :
    : I think I missed something in my PHP journey. Are there no static object methods in PHP (prior to 5, which I haven't even looked into yet)? I'm trying to wrap objects around my DB tables and giving each a select($id) method that is called on the class level and returns an instance... IE:
    :
    : [code]$myAcct = Accounts->Select($id);[/code]
    :
    : Is that not possible? Is there a workaround that's not more complicated than it's worth? I'm trying to avoid a DB wrapper class that's nothing but a series of variously named functions like selectAccount($id), selectUser($id), ...
    :
    : Any help would be appreciated.
    :
    : T
    :
    use [code]Accounts::Select($id)[/code] as Select is a static function.
  • tvientitvienti Posts: 230Member
    That's great! Such a simple thing makes such a big difference to my design. Thank you very much for your help.

    T

    : : Hey,
    : :
    : : I think I missed something in my PHP journey. Are there no static object methods in PHP (prior to 5, which I haven't even looked into yet)? I'm trying to wrap objects around my DB tables and giving each a select($id) method that is called on the class level and returns an instance... IE:
    : :
    : : [code]$myAcct = Accounts->Select($id);[/code]
    : :
    : : Is that not possible? Is there a workaround that's not more complicated than it's worth? I'm trying to avoid a DB wrapper class that's nothing but a series of variously named functions like selectAccount($id), selectUser($id), ...
    : :
    : : Any help would be appreciated.
    : :
    : : T
    : :
    : use [code]Accounts::Select($id)[/code] as Select is a static function.
    :

Sign In or Register to comment.