livethedead
Members-
Posts
77 -
Joined
-
Last visited
Never
Everything posted by livethedead
-
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; } } ?>
-
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.
-
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(); }
-
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
-
Write a query to and store the data. $query_string = ""; $data = mysql_query($query_string);
-
$resid3 = "UPDATE racedata SET s1-3rd = '{$residual3}' "; You need to concatenate your variables within the query {} else its just a string.
-
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.
-
Pretty simple queries.. http://php.net/manual/en/function.date.php
-
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.
-
Hahaha oh dear /facepalm.
-
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; }
-
Which PHP Editor do you think is the best? [v2]
livethedead replied to Daniel0's topic in Miscellaneous
I use Geany. I like it over GEdit. -
Anyone have any ideas for short projects/assignments?
livethedead replied to RORJACK's topic in Miscellaneous
I think that would be superb. -
Alright, now I understand how I was going against OOP principles, thanks much.
-
Ah, I thought that was the purpose of :: I'll do more research, thank you.
-
I'm not really trying to do anything per-say, just fiddling to understand. Thanks for taking the time though ^^. I still don't understand why that would be a syntax error, since Poodle extends Dog, why can't I use :: to call bark() from the parent class? Sorry for the original question being so vague.
-
I just started my journey into OOP, just looking for a simple explanation as to why the script echo's nothing. (last line) <?php class Dog { public $name; public function bark() { echo "{$this->name} says Woof!"; } } class Poodle extends Dog { public function bark() { echo "Yip"; } } $furball = new Poodle; $furball->name = "furball"; $furball->Dog::bark(); ?>
-
Mock Up of the Day/Week
livethedead replied to livethedead's topic in PHPFreaks.com Website Feedback
Sorry I haven't gotten around to replying to the thread. I just made a move from Moline, Illinois to Indianapolis, IN took about a week breather haha. Anyways I wasn't even thinking about prizes when I wrote the thread, though that would be pretty cool. I just thought about it for the sake of bettering y(our)selves. But then again I suppose nobody would compete if that was the case like you guys were saying haha . -
Well, as a PHP newbie and learning on my own; I'm realising I have lack of things to actually work on. I believe the best way to learn is to do. I was thinking that an admin, or a knowledgeable member could create a thread or board where a challenge(s) is posted every day/week in varying difficultly. Giving members who are learning for the sake of learning, rather than learning with a specific short-term goal, something to challenge themselves with. I think this would go over quite well. Sincerely, livethedead
-
I got it now, thanks guys.
-
I'm just trying to figure out how the nested loop acts that way. OK so the first iteration is $i =1 $j = 1 I understand that. How though, is $i not 2 on the second iteration when the action is $i++?
-
Sorry that was kind of a half-assed question, I was expecting an output like: 1, 1 2, 2
-
I'm a bit confused here on for loops. I don't quite understand why this script outputs what it does and I'd like it if someone could explain it to me. <?php for ($i = 1; $i < 3; $i = $i + 1) { for ($j = 1; $j < 3; $j = $j + 1) { echo "'i' is {$i}, 'j' is {$j}<br />"; } } ?> Result: 'i' is 1, 'j' is 1 'i' is 1, 'j' is 2 'i' is 2, 'j' is 1 'i' is 2, 'j' is 2
-
@Joe I'm with ya' there, I prefer to do my studying in books if at all possible. I like to highlight, take notes, and I like to reference back and forth with the ease of flipping a few pages. I just got the book yesterday, so far I'm loving it. While I'm noticing somethings are outdated, it goes very in-depth about how things actually work while not getting extremely complicated. The author claims he is not trying to make a manual-replacement but more of a enhancement to the manual which is exactly what he does. I think it is going to be well worth the read. I ordered the book used in 'new condition' for $2.22 on Amazon. Upon opening I was amazed that the book literally looked like brand freaking new. The used book service is quite useful, I would have payed $29.99.
-
Ah, I see. I don't quite understand how there is a difference between the two though. I take that back, after looking at it I understand. Appreciate it.