livethedead Posted May 30, 2012 Share Posted May 30, 2012 Alright so, firstly this script serves no real purpose other than me practicing OOP. The problem is, I want to get the key of the value _input_word from Library::_translators. I can't seem to figure out why its not working I've been trying to debug it and figured out the problem is occurring at the array_search function. Theres no actual error though because it all executes but I am not getting a key. On a side note I'm sure I horridly used exceptions wrong so feel free to point out any suggestions there if you'd like. I realize I could of wrote this much much easier structurally but like I said, for practice. Here's the problem section: private function makeTranslation() { $check = getCheck(); if ($check = true) { $this->_key = array_search(getInput(), Library::$_translators); $this->_translation = Library::$_translations[$this->_key]; } else { try { throw new Exception("fuuu"); } catch(Exception $e) { echo $e->getMessage(); } } } Here's the whole code. <?php abstract class Library { static $_translators = array("what the fuck", "thank you", "see ya"); static $_translations = array("wtf", "ty", "cya"); } class Input extends Library { private $_input_word; private $_check; function __construct($input) { if (in_array($input, Library::$_translators)) { $this->_input_word = $input; $this->_check = true; } else { try { if (!$this->_check) { throw new Exception("Word not found in library."); } } catch(Exception $e) { echo $e->getMessage(); } } } protected function getInput() { return $this->_input_word; } protected function getCheck() { return $this->_check; } } abstract class Translation extends Input { private $_translation; private $_key; private function makeTranslation() { $check = getCheck(); if ($check = true) { $this->_key = array_search(getInput(), Library::$_translators); $this->_translation = Library::$_translations["{$key}"]; } else { try { throw new Exception("fuuu"); } catch(Exception $e) { echo $e->getMessage(); } } } protected function getTranslation() { return $this->_translation; } } final class Output extends Translation { private $_trans_output; public function makeTranslation() { parent::makeTranslation(); $this->_trans_output = parent::getTranslation(); } public function getTranslation() { return $this->_trans_output; } } ?> Link to comment https://forums.phpfreaks.com/topic/263384-array_search-from-static-property/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.