How to do "friend class" in php?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yarco

    How to do "friend class" in php?

    In c++ we could modify the private variable in a class use friend
    keyword.
    How could it be done in php?

    class YourBag
    {
    int money;

    friend class Thief; // friend?
    };

  • Willem Bogaerts

    #2
    Re: How to do "friend class" in php?

    There is no "friend" or package visibility. Sorry.

    Yarco wrote:
    In c++ we could modify the private variable in a class use friend
    keyword.
    How could it be done in php?
    >
    class YourBag
    {
    int money;
    >
    friend class Thief; // friend?
    };
    >
    Best regards
    --
    Willem Bogaerts

    Application smith
    Kratz B.V.

    Comment

    • Harrie Verveer

      #3
      Re: How to do "friend class" in php?

      Check out the discussion here: http://bugs.php.net/bug.php?id=34044

      Last comment:
      "Long ago we decided against 'friend' declarations."

      Kind regards,

      Harrie Verveer
      ---
      Technisch internetbureau voor bedrijfskritische websites, webapplicaties en mobiele apps. Cloud-native ontwikkeling, PHP, Symfony, Laravel, React



      Willem Bogaerts wrote:
      There is no "friend" or package visibility. Sorry.
      >
      Yarco wrote:
      >In c++ we could modify the private variable in a class use friend
      >keyword.
      >How could it be done in php?
      >>
      >class YourBag
      >{
      > int money;
      >>
      > friend class Thief; // friend?
      >};
      >>
      Best regards

      Comment

      • Toby A Inkster

        #4
        Re: How to do "friend class" in php?

        Harrie Verveer wrote:
        Check out the discussion here: http://bugs.php.net/bug.php?id=34044
        The comments on that page also include a rather nice way of implementing
        friend classes yourself, though you may also want to overload __call().

        Although a little more fiddly, the above method is arguably better than
        C++'s. This is because with a little extra work you could define an
        "acquaintan ce" class which is, say, the same as a friend class, but has
        read-only access to object properties instead of read-write.

        --
        Toby A Inkster BSc (Hons) ARCS
        [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
        [OS: Linux 2.6.12-12mdksmp, up 27 days, 15:49.]

        PHP Linkifier

        Comment

        • gosha bine

          #5
          Re: How to do "friend class" in php?

          On 18.07.2007 14:14 Toby A Inkster wrote:
          Harrie Verveer wrote:
          >
          >Check out the discussion here: http://bugs.php.net/bug.php?id=34044
          >
          The comments on that page also include a rather nice way of implementing
          friend classes yourself, though you may also want to overload __call().
          >
          Although a little more fiddly, the above method is arguably better than
          C++'s. This is because with a little extra work you could define an
          "acquaintan ce" class which is, say, the same as a friend class, but has
          read-only access to object properties instead of read-write.
          >
          Using debug_backtrace to obtain the name of the calling class... well,
          this is not what I'd actually call "nice". Looks quite ugly, but so is
          the very idea of "friends", so it's fair, at least. ;)



          --
          gosha bine

          extended php parser ~ http://code.google.com/p/pihipi
          blok ~ http://www.tagarga.com/blok

          Comment

          Working...