Jump to content

livethedead

Members
  • Posts

    77
  • Joined

  • Last visited

    Never

About livethedead

  • Birthday 10/22/1991

Profile Information

  • Gender
    Male

livethedead's Achievements

Member

Member (2/5)

0

Reputation

  1. 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; } } ?>
  2. Ahhh ok I see, I was looking at exceptions in the manual and just kinda rolled with it without realizing I was just writing code inside a class. Thanks for pointing that out, I was about to pull my hair out.
  3. Ok so I'm pretty new at this can't seem to figure out why I keep getting: Parse error: syntax error, unexpected T_TRY, expecting T_FUNCTION function __construct($input) { if (in_array($this->_input_word, Library::$_translators )) { $this->_input_word = $input; $this->_check = true; } else { throw new Exception("Word not found in library."); } } try {} catch(Exception $e) { echo $e->getMessage(); die(); }
  4. All your variables within your queries need to be concatenated. Whats being stored in your database is the literal string "$whatever". You're query string is no different from a normal string if you want to think of it like that. x = "blah"; echo "something = '$x' somethingelse"; //returns something = '$x' somethingelse echo "something = {$x} somethingelse"; //returns something = blah somethingelse; //you can also concatenate like this echo "blah" . $someVar . "blah blah"; //both work
  5. Write a query to and store the data. $query_string = ""; $data = mysql_query($query_string);
  6. $resid3 = "UPDATE racedata SET s1-3rd = '{$residual3}' "; You need to concatenate your variables within the query {} else its just a string.
  7. Alright so I've been looking through some OOP and I have a few questions regarding principles that are somewhat still foggy for me. In an abstract class should all properties and methods be static? Is it acceptable for example to have a private property with a static getter method? I'll probably be adding more to this thread as I'm trying to do some applying of my knowledge. Thanks.
  8. Pretty simple queries.. http://php.net/manual/en/function.date.php
  9. Hey there guys, recently I've been studying OOP tutorials and such. I'm to the point where I feel I have a pretty good grasp on the concepts and I'm trying to think of a project to work on just for applying skills and learning but I've come up dry. Just looking for some basic project examples would appreciate any. Thanks.
  10. This isn't for anything practical, I'm just fiddling. Anyways, I'm wondering if there's anyway to make this more efficient since at higher lengths it could become really heavy. $l is length of the number. function fixed_random($l) { $number = ""; do { $r = mt_rand(0, $l); $number .= $r; } while (strlen($number) < $l); return $number; }
  11. Alright, now I understand how I was going against OOP principles, thanks much.
  12. Ah, I thought that was the purpose of :: I'll do more research, thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.