Skip to content

Radio Class (Version 1)

Radio.php - OOP in PHP: Complete Code Listing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
    class Radio
    {
        private $powered;   // true or false
        private $volume;    // 0 - 10
        private $channel;   // 535kHz - 1700kHz, 87.5MHz - 108MHz

        // Getters
        public function getPowered()
        {
            return $this->powered;
        }

        public function getVolume()
        {
            return $this->volume;
        }

        public function getChannel()
        {
            return $this->channel;
        }

        // Setters
        public function setPowered($powered)
        {
            $this->powered = $powered;
        }

        public function setVolume($volume)
        {
            $this->volume = $volume;
        }

        public function setChannel($channel)
        {
            $this->channel = $channel;
        }

        // General Methods
        public function scanChannels() 
        {
            // find the next channel with a strong signal
        }

        public function getCurrentSong() 
        {
            // reads live metadata from current channel about current song
            // being played and returns song title, etc...
        }
    }