473,322 Members | 1,408 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.

class problem

Hi,

When executing the code below, expecting to say that the apple is green
and later red I get the error

Parse error: parse error, expecting `T_VARIABLE' in /httpdocs/test01.php
on line 3

Any idea how I can fix this?

Thanks in advance,

Roderik

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class apple {
  3. var color;
  4.  
  5. function apple() {
  6. color = "green";
  7. }
  8. }
  9.  
  10. class banana {
  11. var color;
  12.  
  13. function banana() {
  14. color = "green";
  15. }
  16. }
  17.  
  18. var red_apple = new apple();
  19. var yellow_banana = new banana();
  20. ?>
  21.  
  22. <html>
  23. <head></head>
  24. <body>
  25. <?
  26. print("The color of our apple is ".red_apple->color);
  27. red_apple->color = "red";
  28. print("Some weeks later the color of our apple is ".red_apple->color);
  29. ?>
  30.  
  31. </body>
  32. </html>
  33.  
--
http://www.archytas.nl/
webdesign, internet applicaties, internetgestuurde elektronica
Jul 17 '05 #1
6 1864
Roderik a écrit :
Hi,

When executing the code below, expecting to say that the apple is green
and later red I get the error

Parse error: parse error, expecting `T_VARIABLE' in /httpdocs/test01.php
on line 3

Any idea how I can fix this?
[code]
<?php
class apple {
var color; var $color;
function apple() {
color = "green";

$color = "green";

but doing so, $color will be a local variable.
you want :
$this->color = "green";

And take some time to read the manual -- it may help.

Bruno
Jul 17 '05 #2
bruno modulix wrote:
Roderik a écrit :
Hi,

When executing the code below, expecting to say that the apple is
green and later red I get the error

Parse error: parse error, expecting `T_VARIABLE' in
/httpdocs/test01.php on line 3

Any idea how I can fix this?
[code]
<?php
class apple {
var color;


var $color;
function apple() {
color = "green";


$color = "green";

but doing so, $color will be a local variable.
you want :
$this->color = "green";

And take some time to read the manual -- it may help.

Bruno


excuse me, I made very dirty code for the example now. I'll post a new
one. The problem is still there.
--
http://www.archytas.nl/
webdesign, internet applicaties, internetgestuurde elektronica
Jul 17 '05 #3
Hi,

Here again the question with some more clear (but still errornous) code.
I get the error:

Parse error: parse error in /httpdocs/test01.php on line 10

Any idea what the problem might be?

Thanks in advance,

Roderik

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class apple {
  3. var $color;
  4.  
  5. function apple() {
  6. $this->color = "green";
  7. }
  8. }
  9.  
  10. var red_apple = new apple();  // line 10
  11. //var yellow_banana = new banana();
  12. ?>
  13.  
  14. <html>
  15. <head></head>
  16. <body>
  17. <?
  18. print("The color of our apple is ".$red_apple->color);
  19. red_apple->color = "red";
  20. print("Some weeks later the color of our apple is ".$red_apple->color);
  21. ?>
  22. </body>
  23. </html>
  24.  
Jul 17 '05 #4
Roderik wrote:
Hi,

Here again the question with some more clear (but still errornous) code.
I get the error:

Parse error: parse error in /httpdocs/test01.php on line 10

Any idea what the problem might be?

Thanks in advance,

Roderik

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  class apple {
  3.      var $color;
  4.      function apple() {
  5.          $this->color = "green";
  6.      }
  7.  }
  8.  var red_apple = new apple();  // line 10
  9.  //var yellow_banana = new banana();
  10.  ?>
  11.  <html>
  12.  <head></head>
  13.  <body>
  14.          <?
  15.   print("The color of our apple is ".$red_apple->color);
  16.   red_apple->color = "red";
  17.   print("Some weeks later the color of our apple is ".$red_apple->color);
  18.  ?>
  19.      </body>
  20.  </html>
  21.  


Ow now I see, I am not commercially enough. I still forgot to place some
dollar signs. But it is fixed now.

--
http://www.archytas.nl/
webdesign, internet applicaties, internetgestuurde elektronica
Jul 17 '05 #5
Roderik wrote:
Parse error: parse error in /httpdocs/test01.php on line 10 <snip> var red_apple = new apple(); // line 10


http://www.php.net/manual/en/language.variables.php
Jul 17 '05 #6
Roderik a écrit :
Hi,

Here again the question with some more clear (but still errornous) code.
I get the error:

Parse error: parse error in /httpdocs/test01.php on line 10

Any idea what the problem might be?

Thanks in advance,

Roderik

[code]
<?php
class apple {
var $color;

function apple() {
$this->color = "green";
}
}

var red_apple = new apple(); // line 10


s/var//
s/red_apple/$red_apple/

And definitively : RTFM !

Bruno
Jul 17 '05 #7

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

Similar topics

1
by: Steve | last post by:
Hello, I'm encountering an unexpected behavior when using the "new" modifier in a derived class to hide an inherited base class property. I use "new" intentionally so I can change the Type of...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
21
by: Mark Broadbent | last post by:
Consider the following statements //------- Item i = Basket.Items; //indexer is used to return instance of class Item Basket.Items.Remove(); //method on class item is fired item i = new...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
8
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
3
by: TamusJRoyce | last post by:
Hello. This is my first thread here. My problem has probably been came across by a lot of people, but tutorials and things I've seen don't address it (usually too basic). My problem is that I...
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: 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: 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: 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.