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";

preferences:
23.41 ms | 409 KiB | 5 Q