473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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?
};

Jul 18 '07 #1
4 17046
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.
http://www.kratz.nl/
Jul 18 '07 #2
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
---
http://www.ibuildings.nl/blog/authors/Harrie-Verveer
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
Jul 18 '07 #3
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
"acquaintance" 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
http://tobyinkster.co.uk/blog/2007/07/18/linkify/
Jul 18 '07 #4
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
"acquaintance" 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
Jul 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: dpr | last post by:
I have come accross a piece of C++ code with the construct: MyClass *c = new class MyClass(); Is there a difference between this and: MyClass *c = new MyClass(); ?
0
by: Gianni Mariani | last post by:
It started out as an ugly hack and it turned out to be very easy to do but I'm concerned about wether I'm not seeing somthing so I'm asking the wise ladies and gents of clc++ as to wether they turn...
6
by: Stephen Johns | last post by:
I want to have a Hashtable whose keys are strings and whose values are delegates. Well, ok, I have that: dels = new Hastable(); dels.Add( "key", new Foo1Delegate(MyFoo1) ); dels.Add( "key",...
9
by: Neil Kiser | last post by:
I'm trying to understand what defining a class as 'static' does for me. Here's an example, because maybe I am thinking about this all wrong: My app will allows the user to control the fonts...
0
by: Winterminute | last post by:
I am trying to read a list of install programs using WMI with ASP.NET/C#. However, it fails with "Invalid Class". I have confirmed that if I query LOCALHOST then it works fine, but if I query a...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
0
by: Jaime Lucci | last post by:
Hi everyone! I have a problem that I can't resolve. In VB2005 I've programmed a new class, where I use a Windows Form with four controls: a SplitContainer, a Panel, a Label and a...
3
by: Matt | last post by:
Hi everyone, can someone point out the difference between defining a class with the public access modifier and just leaving it as it is (default in vs.net "class") I think that the default...
3
by: Ravi | last post by:
Is this the correct way to think of "base class"? The "base class" is a class from which other classes are derived. The "base class" will never be derived from another class.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.