473,383 Members | 1,759 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,383 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 1867
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: 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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.