473,325 Members | 2,870 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,325 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 2708
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'
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...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.