3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AuxiliaryVerbQuestion { private $iHaveNoClue = [ 'Why do you think I can answer that?', 'Why are you asking me?', 'Try asking @Danack', 'What are you even saying?', 'Why do you even care?', 'Who the hell are you?', 'Why are you asking?', 'You know I\'m a bot, right?', 'Wanna buy some weed?', 'WHAT YEAR IS IT??????', 'Wanna get high?', 'Who am I?', '42.', ]; private $singleOption = [ 'Possibly?', 'Probably?', 'Maybe?', 'No!!!!!!111one', 'Yes!!!!!!111one', 'No.', 'Yes.', 'Nope.', 'Yep.', 'I don\'t think so...', 'I think so...', 'Negative.', 'Affirmative.', 'Definitely no! ...right?', 'Definitely yes! ...right?', 'Granted.', 'Indeed.', ]; private $twoOptions = [ 'I\'m gonna say the former.', 'I\'m gonna say the latter.', ]; private $severalOptions = [ 'I\'d say %%%', ]; function __construct(){ $this->singleOption = array_merge($this->singleOption, $this->iHaveNoClue); } function answer($question){ echo $question . " \n"; $verbs = 'is|are|can|could|do|does|have|has|may|might|shall|should|will|would'; preg_match('@^ (' . $verbs . ') \s+ (.+?) \s+ (.+) \s* ? \s*$@x', $question, $matches); list(, $verb, $who, $options) = $matches; $options = explode("or", $options); foreach($options as $i => $option){ $options[$i] = trim($option); } if(count($options) === 1){ $answers = $this->singleOption; }else{ $answers = $this->severalOptions; if(count($options) === 2){ $answers = array_merge($answers, $this->twoOptions); } } return $answers[random_int(0, count($answers) - 1)]; } } $x = new AuxiliaryVerbQuestion(); print_r($x->answer('is @PeeHaa skynet?')); echo "\n\n";
Output for 7.0.10, 7.0.20, 7.3.2, 7.3.10, 7.4.5, 8.0.3
is @PeeHaa skynet? Why are you asking?
Output for 7.0.22, 7.1.3, 7.1.7, 7.1.17, 7.2.3, 7.2.12, 8.0.2
is @PeeHaa skynet? What are you even saying?
Output for 7.0.33, 7.1.5, 7.1.23, 7.2.0, 7.3.0, 7.3.20, 8.0.1
is @PeeHaa skynet? Definitely no! ...right?
Output for 7.0.23, 7.1.9, 7.1.25, 7.2.15, 7.2.19, 8.0.0
is @PeeHaa skynet? Try asking @Danack
Output for 7.0.21, 7.0.27, 7.1.0, 7.1.32, 7.3.11, 7.3.19, 7.4.16
is @PeeHaa skynet? Definitely yes! ...right?
Output for 7.0.12, 7.1.12, 7.2.23, 7.4.15
is @PeeHaa skynet? 42.
Output for 7.2.34, 7.3.8, 7.3.23, 7.4.1, 7.4.14
is @PeeHaa skynet? Indeed.
Output for 7.2.1, 7.2.10, 7.2.25, 7.3.14, 7.4.13
is @PeeHaa skynet? I don't think so...
Output for 7.0.14, 7.1.19, 7.2.32, 7.3.17, 7.4.12
is @PeeHaa skynet? Yes!!!!!!111one
Output for 7.2.11, 7.2.16, 7.4.11
is @PeeHaa skynet? No.
Output for 7.0.9, 7.1.2, 7.3.21, 7.4.4, 7.4.6, 7.4.10
is @PeeHaa skynet? Affirmative.
Output for 7.0.0, 7.1.6, 7.2.31, 7.4.3, 7.4.9
is @PeeHaa skynet? Why do you think I can answer that?
Output for 7.0.5, 7.0.8, 7.0.24 - 7.0.25, 7.1.31, 7.3.6, 7.3.12, 7.3.16, 7.4.0, 7.4.8
is @PeeHaa skynet? You know I'm a bot, right?
Output for 7.0.13, 7.0.15, 7.2.8, 7.4.2, 7.4.7
is @PeeHaa skynet? No!!!!!!111one
Output for 7.3.18, 7.3.27
is @PeeHaa skynet? Why are you asking me?
Output for 7.0.32, 7.1.10, 7.1.20, 7.1.26, 7.2.6, 7.3.13, 7.3.26
is @PeeHaa skynet? Wanna buy some weed?
Output for 7.0.26, 7.1.27, 7.3.15, 7.3.25
is @PeeHaa skynet? Wanna get high?
Output for 7.0.30, 7.1.13, 7.1.28, 7.3.9, 7.3.24
is @PeeHaa skynet? Negative.
Output for 7.0.6, 7.1.4, 7.1.8, 7.3.3 - 7.3.4, 7.3.22
is @PeeHaa skynet? I think so...
Output for 7.0.11, 7.0.18, 7.1.11, 7.2.5, 7.2.18, 7.2.20, 7.2.22, 7.2.26, 7.3.1, 7.3.7
is @PeeHaa skynet? Who the hell are you?
Output for 7.1.24, 7.2.29, 7.3.5
is @PeeHaa skynet? Who am I?
Output for 7.0.17, 7.2.24, 7.2.33
is @PeeHaa skynet? Possibly?
Output for 7.0.31, 7.1.14, 7.2.30
is @PeeHaa skynet? Granted.
Output for 7.0.1, 7.1.1, 7.1.15, 7.1.29, 7.2.28
is @PeeHaa skynet? Probably?
Output for 7.0.3, 7.0.7, 7.1.16, 7.1.21, 7.2.9, 7.2.17, 7.2.21, 7.2.27
is @PeeHaa skynet? Nope.
Output for 7.1.18, 7.1.33, 7.2.4, 7.2.14
is @PeeHaa skynet? Yep.
Output for 7.0.16, 7.2.7, 7.2.13
is @PeeHaa skynet? Yes.
Output for 7.0.19, 7.1.22, 7.2.2
is @PeeHaa skynet? WHAT YEAR IS IT??????
Output for 7.0.28 - 7.0.29, 7.1.30
is @PeeHaa skynet? Why do you even care?
Output for 7.0.2, 7.0.4
is @PeeHaa skynet? Maybe?
Output for 5.5.10 - 5.5.38, 5.6.0 - 5.6.40
is @PeeHaa skynet? Fatal error: Call to undefined function random_int() in /in/GHHkb on line 70
Process exited with code 255.
Output for 5.5.0 - 5.5.9
is @PeeHaa skynet? Warning: preg_match(): Compilation failed: nothing to repeat at offset 95 in /in/GHHkb on line 54 Fatal error: Call to undefined function random_int() in /in/GHHkb on line 70
Process exited with code 255.

preferences:
58.02 ms | 449 KiB | 5 Q