472,794 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

get object value

I have the following class shop and function. makelist
makelist() function is going to generate the dummy data for testing.

At the end when displaying the id and shopname I only get the shopname for
both $shoplist[$i]->getID() and $shoplist[$i]->getName() why is that?

Class Shop{
var mID;
var mName;

function setID( $id ){
$this->$mID=$id;
}
function getID(){
return $this->$mID;
}
function setName( $name ){
$this->$mName=$name;
}
function getName(){
return $this->$mName;
}
}

function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
$shoplist = makelist();

for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$i]->getID()."Name: ".$shoplist[$i]->getName();
}
}
Aug 14 '06 #1
7 2687
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.

<?php
Class Shop{
var $mID;
var $mName;

function setID( $id ){
$this->mID=$id;
}

function getID(){
return $this->mID;
}

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

function getName(){
return $this->mName;

}
}

function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

$shoplist = makelist();

for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$j]->getID()."Name:
".$shoplist[$j]->getName();
}

?>

Aug 14 '06 #2
ImOk wrote:
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.
[snip code]
function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
[snip code]

I think you want to change you makelist() function to look like this:

function makelist( )
{
$vector = array();

for( $i=0;$i<10;$i++)
{
$aShop = new Shop();
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 14 '06 #3
ImOk wrote:
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.
[snip code]
function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
[snip code]

I think you want to change you makelist() function to look like this:

function makelist( )
{
$vector = array();

for( $i=0;$i<10;$i++)
{
$aShop = new Shop();
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 14 '06 #4
ImOk wrote:
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.
[snip code]
function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
[snip code]

I think you want to change you makelist() function to look like this:

function makelist( )
{
$vector = array();

for( $i=0;$i<10;$i++)
{
$aShop = new Shop();
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 14 '06 #5
ImOk wrote:
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.
[snip code]
function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}
[snip code]

I think you want to change you makelist() function to look like this:

function makelist()
{
$vector = array();
for( $i=0;$i<10;$i++)
{
$aShop = new Shop();
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 14 '06 #6
Thanks,
It seems working now.

mz

"ImOk" <jo**********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.

<?php
Class Shop{
var $mID;
var $mName;

function setID( $id ){
$this->mID=$id;
}

function getID(){
return $this->mID;
}

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

function getName(){
return $this->mName;

}
}

function makelist( ){
$vector=array();
$aShop = new Shop();
for( $i=0;$i<10;$i++){
$aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

$shoplist = makelist();

for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$j]->getID()."Name:
".$shoplist[$j]->getName();
}

?>

Aug 14 '06 #7
Mike Zhang wrote:
Thanks,
It seems working now.

mz

"ImOk" <jo**********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>Did you even run this code? Your code is full of syntax and runtime
errors. Here is the fixed up version.

<?php
Class Shop{
var $mID;
var $mName;

function setID( $id ){
$this->mID=$id;
}

function getID(){
return $this->mID;
}

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

function getName(){
return $this->mName;

}
}

function makelist( ){
$vector=array();
Not sure how you can say that this works. Yes this will generate 10
instances of the "same thing". You need to move the $aShop = new Shop();
into your loop. This will then generate the 10 instances but the data in
the instances will be different.
> for( $i=0;$i<10;$i++){
$aShop = new Shop();
> $aShop->setID($i);
$aShop->setName("shopname".$i);
$vector[]=$aShop;
}
return $vector;
}

$shoplist = makelist();

for( $j=0;$j<10;$j++){
echo "ID: " . $shoplist[$j]->getID()."Name:
".$shoplist[$j]->getName();
}

?>

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 14 '06 #8

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
11
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for...
9
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes...
5
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2...
8
by: a | last post by:
I'm trying to save data from a custom object into the profile object, but it is not structured the way that I want. I'm trying to get the custom object to serialize as xml to a Profile object...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.