473,396 Members | 1,891 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,396 software developers and data experts.

Referencing objects?

Fairly new to OOP and PHP5.
My question;

Maybe I am not thinking about this the right way? How do I reference a
variable or object(?) from one function to another in a class? Or how
do I pass the variable from one function or method to another? Am I
doing this right in the example below? How would I pass a variable from
one function to another?

Example ================================================== ========

class NAME {
public $name;
public $unknown;
public $value;
function __construct($value) {
$this->setName($this->value);
}

function setName($value) {
$this->name = $value;
}

function getName() {
return $this->name;
}

function nameKid($unknown) {
$this->setName($unkown);
}
} // end class
$boy = new NAME("Joe");
$boy->getName();

Joe

END EXAMPLE ================================================== ====
Thanks,
Schmidty

Jan 13 '07 #1
2 1044
Schmidty wrote:
Fairly new to OOP and PHP5.
<snip>
>
Example ================================================== ========

class NAME {
public $name;
public $unknown;
public $value;
function __construct($value) {
$this->setName($this->value);
no - I guess you want to assign the value in the parameter using the setName
method...
$this->setName($value);
}

function setName($value) {
$this->name = $value;
Yup - just like that
}

function getName() {
return $this->name;
}

function nameKid($unknown) {
$this->setName($unkown);
erm, not sure what this is trying to (even without the typo).

Looks like your nearly there.

HTH

C.
Jan 13 '07 #2
Sorry about the typo, it should be '$unknown'. Thanks for the help!! :)
Schmidty
Colin McKinnon wrote:
Schmidty wrote:
Fairly new to OOP and PHP5.
<snip>

Example ================================================== ========

class NAME {
public $name;
public $unknown;
public $value;
function __construct($value) {
$this->setName($this->value);

no - I guess you want to assign the value in the parameter using the setName
method...
$this->setName($value);
}

function setName($value) {
$this->name = $value;

Yup - just like that
}

function getName() {
return $this->name;
}

function nameKid($unknown) {
$this->setName($unkown);
erm, not sure what this is trying to (even without the typo).

Looks like your nearly there.

HTH

C.
Jan 13 '07 #3

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

Similar topics

11
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
1
by: Faktor_one | last post by:
Does referencing objects increase memory consumption? For example, if I call public function in one form from another form and give "this" as argument, is it just pointing to the form or does it...
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
2
by: SpamProof | last post by:
I'm creating a new application that will use/need to refer to some business objects I have in another separate application. What the best way to do this? It appears that adding a reference and...
2
by: Terry | last post by:
What is the syntax for referencing the properties of objects within Collections of objects? EXAMPLE: Dim MCoil As New Coil MCoil = CoilCollection("3456") TextBox1.Text() = MCoil.CoilDesc ...
3
by: Varangian | last post by:
I made an MFC DLL in C++ . I want to reference it in C#. However I don't know where to put the function to be called from C# ? After referencing the DLL no methods are visible in the C# object...
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
2
by: Olivier Feys | last post by:
I'm working on a tree and I have refcounting problems. Is it possible from an object, to get the list of objects referencing it ? thanks
2
by: Lakenarr | last post by:
Hi, I need to have two objects referencing eash other. Something like this: class Planet { private Moon m_Moon; public Moon Moon {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.