• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1899
  • Last Modified:

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

<?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
rgb192
Asked:
rgb192
3 Solutions
 
ienaxxxCommented:
...
  public function SitAtBar(){
....
0
 
ienaxxxCommented:
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
 
ienaxxxCommented:
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
Technology Partners: 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!

 
Dan CraciunIT ConsultantCommented:
@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
 
ienaxxxCommented:
Uh, wow.

Sorry: i was sure xampp was the evolution of wampp...
:-(
then @rgb192 : can you post a phpinfo(), please?
0
 
rgb192Author Commented:
line 38:
public function SitAtBar(){

can 'void' be used because tutorial was an example of 'void'
0
 
Slick812Commented:
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
 
rgb192Author Commented:
Thanks for the echo information which I will have a new question on how to output by calling the object
0

Featured Post

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now