Solved

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\oop-beg\ch4-7.php on line 38

Posted on 2013-12-09
8
1,572 Views
Last Modified: 2013-12-09
<?php
class Person{}
class Vegetable{}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){}
  public function SmileAtYou(){}
  public function TalkToYou(){}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){}
  public function CauseBathroomEmergency(){}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $thingsThatMakeYouSweat=array($thing1,$thing2);
    SitAtBar($thingsThatMakeYouSweat);
  }
  void SitAtBar(){
    //when you are sitting at the Bar
    foreach($thingsThatMakeYouSweat as $value){
      
    }
  }
}

Open in new window


from an object oriented php tutorial

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\wamp\www\oop-beg\ch4-7.php on line 38

and how could an object be created and an object instance called
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Assisted Solution

by:ienaxxx
ienaxxx earned 125 total points
ID: 39705943
...
  public function SitAtBar(){
....
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39705945
To create a new instance, after the ending brackets of the class:

$obj = new CollegeBar();

to call the object method SitAtBar:

$obj->SitAtBar();

Hope this helps
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39705951
Ah, this kind of error is probably because you are using a very old version of PHP (i guess it from the path, that contains WAMPP, instead of XAMPP. That name has been switched a lot of time ago).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 125 total points
ID: 39706033
@ienaxxx: WAMP ( http://www.wampserver.com/en/ ) and XAMPP ( http://www.apachefriends.org/en/xampp.html ), are 2 separate packages, both actively maintained.

HTH,
Dan
0
 
LVL 10

Expert Comment

by:ienaxxx
ID: 39706061
Uh, wow.

Sorry: i was sure xampp was the evolution of wampp...
:-(
then @rgb192 : can you post a phpinfo(), please?
0
 

Author Comment

by:rgb192
ID: 39706367
line 38:
public function SitAtBar(){

can 'void' be used because tutorial was an example of 'void'
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 250 total points
ID: 39706509
greetings  rgb192, , The programming term 'void' is used in other programming languages as a way to say the a "function" does not return a result, it returns nothing at all. However in PHP you can not use 'void', especially with a function as you did with -
void SitAtBar(){
    this is totally incorrect PHP syntax. It is posible that your tutorial was showing you a "Code" example in another language to help you, but you can not use 'void' in PHP.

I looked at your code example here, and it will not teach you much of anything about Class and Objects in PHP, why, because your parent Classes of-
class Person{}
class Vegetable{}

are EMPTY, you should have at least one property and one method in each, to see how this affects the Child Classes.

also your last Class-CollegeBar is SO BAD CODE, all kinds of Class thinking Errors, and php syntax - formatting errors, you should really be more knowledgeable about writing a PHP Class by now,you have -
class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $thingsThatMakeYouSweat=array($thing1,$thing2);
    SitAtBar($thingsThatMakeYouSweat);
  }
  void SitAtBar(){
    //when you are sitting at the Bar
    foreach($thingsThatMakeYouSweat as $value){
     
    }
  }
}

But you have left out the necessary method for ISweat as- MakeYouSweat()  and you have
  void SitAtBar(){
which should be
  public function SitAtBar($thingsThatMakeYouSweat){

<?php
class Person{public $name='none';
public function echoName(){echo $this->name;}
}
class Vegetable{public $type='none';
public function echoType(){echo $this->type;}
}

interface ISweat{
  function MakeYouSweat();
}

class AttractiveStranger extends Person implements ISweat{
  public function LookAtYou(){echo $this->name.'=LookAtYou-';}
  public function SmileAtYou(){$this->echoName(); echo '=SmileAtYou-';}
  public function TalkToYou(){echo 'SmileAtYou-';}
  
  public function MakeYouSweat(){
    $this->LookAtYou();
    $this->SmileAtYou();
    $this->TalkToYou();
    return 'AttractiveStranger-MakeYouSweat';
  }
}
class Pepper extends Vegetable{
  public function BurnYourTongue(){echo $this->type.'=BurnYourTongue-';}
  public function CauseBathroomEmergency(){$this->echoType();  echo 'CauseBathroomEmergency-';}
  public function MakeYouSweat(){
    $this->BurnYourTongue();
    $this->CauseBathroomEmergency();
    return 'Pepper-MakeYouSweat';
  }
}

class CollegeBar implements ISweat{
  public function __construct(){
    $attractivestranger=new AttractiveStranger();
    $hotpepper=new Pepper();
    $thing1=$attractivestranger->MakeYouSweat();
    $thing2=$hotpepper->MakeYouSweat();
    $arrayValues=array($thing1,$thing2);
    $this->SitAtBar($arrayValues);
  }
  public function SitAtBar($things){
    //when you are sitting at the Bar
    foreach($things as $value){
      echo $value.'-';
    }
  }

  public function MakeYouSweat(){
  echo 'Perspiration';
  }
}

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 39707573
Thanks for the echo information which I will have a new question on how to output by calling the object
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question