Link to home
Create AccountLog in
Avatar of burnedfaceless
burnedfaceless

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of burnedfaceless
burnedfaceless

ASKER

Thanks man.

Now to figure out this encapsulation bulllshit.