can $this be passed as a method parameter?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lkrubner@geocities.com

    can $this be passed as a method parameter?


    In a class, can $this be passed by reference or value?

    function setDatabaseObje ct("MySql", $this) {
    // some code here checks the name of the
    // class of the object that is calling this method
    }

    For security, and to enforce naming conventions, I'd like for some of
    my objects to only be callable from certain classes, but the only way
    I can think for an object to get the name of the calling code is if I
    had in the $this keyword.

  • Tim Van Wassenhove

    #2
    Re: can $this be passed as a method parameter?

    On 2005-02-04, lkrubner@geocit ies.com <lkrubner@geoci ties.com> wrote:[color=blue]
    >
    > In a class, can $this be passed by reference or value?
    >
    > function setDatabaseObje ct("MySql", $this) {
    > // some code here checks the name of the
    > // class of the object that is calling this method
    > }
    >
    > For security, and to enforce naming conventions, I'd like for some of
    > my objects to only be callable from certain classes, but the only way
    > I can think for an object to get the name of the calling code is if I
    > had in the $this keyword.[/color]

    in php5 you would mean something like this?

    function foo($caller, $bar)
    {
    // do something with the reflection api i can find in the manual?
    }

    $class = new Class;
    foo($class, "fubar");




    --
    Met vriendelijke groeten,
    Tim Van Wassenhove <http://www.timvw.info>

    Comment

    • Chung Leong

      #3
      Re: can $this be passed as a method parameter?

      <lkrubner@geoci ties.com> wrote in message
      news:1107476171 .907895.310010@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      >
      > In a class, can $this be passed by reference or value?
      >
      > function setDatabaseObje ct("MySql", $this) {
      > // some code here checks the name of the
      > // class of the object that is calling this method
      > }
      >
      > For security, and to enforce naming conventions, I'd like for some of
      > my objects to only be callable from certain classes, but the only way
      > I can think for an object to get the name of the calling code is if I
      > had in the $this keyword.[/color]

      A situation for debug_backtrace (). Just keep stepping back until you find a
      class name that's permitted.




      Comment

      Working...