We help IT Professionals succeed at work.
Get Started

Parse error: syntax error, unexpected '$triad' (T_VARIABLE)

burnedfaceless
on
112 Views
Last Modified: 2017-11-23
I'm writing my first Object Oriented script and I'm getting the following error

Parse error: syntax error, unexpected '$triad' (T_VARIABLE) in /var/www/html/unademy/public_html/chord-speller/result.php on line 4

Here is my code

result.php

<?php
  include 'MajorTriad.php'

  $triad = new MajorTriad('C');
  echo $triad->getRoot();

?>

Open in new window


MajorTriad.php

<?php

  class MajorTriad {
      private $root;
      private $rootNumber;
      private $third;
      private $thirdNumber;
      private $fifth;
      private $fifthNumber;

      function __construct($root)
      {
          $this->root = $root;
      }

      protected function getChord()
      {
          $this->rootNumber = $this->getCorrespondingRootNumber($this->root);
          $this->thirdNumber = $this->getThirdNumber($this->rootNumber);
          $this->fifthNumber = $this->getFifthNumber($this->rootNumber);
          $this->third = $this->getChordNote($this->root, $this->thirdNumber);
          $this->fifth = $this->getChordNote($this->third, $this->fifthNumber);

          $chord = $this->root . $this->third . $this->fifth;

          return $chord;

      }

      protected function getRoot()
      {
          return $this->root;
      }

      protected function getThird()
      {
          return $this->third;
      }

      protected function getFifth()
      {
          return $this->fifth;
      }


      protected function getThirdNumber($rootNumber)
      {
          $this->thirdNumber = $rootNumber + 4;
      }

      protected function getFifthNumber($rootNumber)
      {
          $this->fifthNumber = $rootNumber + 7;
      }

      protected function getCorrespondingRootNumber($rootNote)
      {
          switch ($rootNote) {
              case 'G♯':
                  $this->rootNumber = 1;
                  break;
              case 'A♭':
                  $this->rootNumber = 1;
                  break;
              case 'A':
                  $this->rootNumber = 2;
                  break;
              case 'A♯':
                  $this->rootNumber = 3;
                  break;
              case 'B♭':
                  $this->rootNumber = 3;
                  break;
              case 'B':
                  $this->rootNumber = 4;
                  break;
              case 'C':
                  $this->rootNumber = 5;
                  break;
              case 'C♯':
                  $this->rootNumber = 6;
                  break;
              case 'D♭':
                  $this->rootNumber = 6;
                  break;
              case 'D':
                  $this->rootNumber = 7;
                  break;
              case 'D♯':
                  $this->rootNumber = 8;
                  break;
              case 'E♭':
                  $this->rootNumber = 8;
                  break;
              case 'E':
                  $this->rootNumber = 9;
                  break;
              case 'F':
                  $this->rootNumber = 10;
                  break;
              case 'F♯':
                  $this->rootNumber = 11;
                  break;
              case 'G♭':
                  $this->rootNumber = 11;
                  break;
              case 'G':
                  $this->rootNumber = 12;
                  break;
              default:
                  die('Error assigning root number');
          }
      }

      protected function getChordNote($thirdBelow, $number)
      {
          $letterNote = $this->getLetter($thirdBelow);
          $currentLetter = $this->thirdUp($letterNote);

          switch ($number) {
              case 1:
                  if (strpos('G♯', $currentLetter)) $chordTone = 'G♯';
                  elseif (strpos('A♭', $currentLetter)) $chordTone = 'A♭';
                  break;
              case 2:
                  if (strpos( 'G𝄪', $currentLetter)) $chordTone = 'G𝄪';
                  elseif (strpos('A', $currentLetter)) $chordTone = 'A';
                  elseif (strpos('B𝄫', $currentLetter)) $chordTone = 'B𝄫';
                  break;
              case 3:
                  if (strpos('A♯', $currentLetter)) $chordTone = 'A♯';
                  elseif (strpos('C𝄫', $currentLetter)) $chordTone = 'C𝄫';
                  elseif (strpos('B♭', $currentLetter)) $chordTone = 'B♭';
                  break;
              case 4:
                  if (strpos('A𝄪', $currentLetter)) $chordTone = 'A𝄪';
                  elseif (strpos('B', $currentLetter)) $chordTone = 'B';
                  elseif (strpos('C♭', $currentLetter)) $chordTone = 'C♭';
                  break;
              case 5:
                  if (strpos('B♯', $currentLetter)) $chordTone = 'B♯';
                  elseif (strpos('C', $currentLetter)) $chordTone = 'C';
                  elseif (strpos('D𝄫', $currentLetter)) $chordTone = 'D𝄫';
                  break;
              case 6:
                  if (strpos('B𝄪', $currentLetter)) $chordTone = 'B𝄪';
                  elseif (strpos('C♯', $currentLetter)) $chordTone = 'C♯';
                  elseif (strpos('D♭', $currentLetter)) $chordTone = 'D♭';
                  break;
              case 7:
                  if (strpos('C𝄪', $currentLetter)) $chordTone = 'C𝄪';
                  elseif (strpos('D', $currentLetter)) $chordTone 'D';
                  elseif (strpos('E𝄫', $currentLetter)) $chordTone = 'E𝄫';
                  break;
              case 8:
                  if (strpos('D♯', $currentLetter)) $chordTone = 'D♯';
                  elseif (strpos('E♭', $currentLetter)) $chordTone = 'E♭';
                  elseif (strpos('F𝄫', $currentLetter)) $chordTone = 'F𝄫';
                  break;
              case 9:
                  if (strpos('D𝄪', $currentLetter)) $chordTone = 'D𝄪';
                  elseif (strpos('E', $currentLetter)) $chordTone = 'E';
                  elseif (strpos ('F♭', $currentLetter)) $chordTone = 'F♭';
                  break;
              case 10:
                  if (strpos('E𝄪', $currentLetter)) $chordTone = 'E♯';
                  elseif (strpos('F', $currentLetter)) $chordTone = 'F';
                  elseif (strpos('G𝄫', $currentLetter)) $chordTone = 'G𝄫';
                  break;
              case 11:
                  if (strpos('E𝄪', $currentLetter)) $chordTone = 'E𝄪';
                  elseif (strpos('F♯', $currentLetter)) $chordTone = 'F♯';
                  elseif (strpos('G♭', $currentLetter)) $chordTone = 'G♭';
                  break;
              case 12:
                  if (strpos('F𝄪', $currentLetter)) $chordTone = 'F𝄪';
                  elseif (strpos('G', $currentLetter)) $chordTone = 'G';
                  elseif (strpos('A𝄫', $currentLetter)) $chordTone = 'A𝄫';
                  break;
              default:
                  die('Error in getChordNote method');
           }
      }


      protected function getLetter($note)
      {
          if (strpos($note, 'A')) $letterNote = 'A';
          elseif (strpos($note, 'B')) $letterNote = 'B';
          elseif (strpos($note, 'C')) $letterNote = 'C';
          elseif (strpos($note, 'D')) $letterNote = 'D';
          elseif (strpos($note, 'E')) $letterNote = 'E';
          elseif (strpos($note, 'F')) $letterNote = 'F';
          elseif (strpos($note, 'G')) $letterNote = 'G';
          else
           {
              $letterNote = null;
              die('error in getLetter method');
          }

          return $letterNote;
      }

      protected function thirdUp($letterNote)
      {
          switch ($letterNote) {
              case 'A':
                  $nextNote = 'C';
                  break;
              case 'B':
                  $nextNote = 'D';
                  break;
              case 'C':
                  $nextNote = 'E';
                  break;
              case 'D':
                  $nextNote = 'F';
                  break;
              case 'E':
                  $nextNote = 'G';
                  break;
              case 'F':
                  $nextNote = 'A';
                  break;
              case 'G':
                  $nextNote = 'B';
                  break;
              default:
                  die('Error in method thirdUp()');
          }
            return $nextNote;
      }

  }
?>

Open in new window


Happy Thanksgiving
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE