-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
You know what I think is funny about people who argue about object oriented programming being 'useless', is that those same people 99.9999999% of the time endorse using functions and properly following scope. They fail to realize that object oriented programming is the same concept, only it just adds another layer of scope to the mix. Yes, most of the time you could have just written your program procedurally, instead of using OOP. But that often misleads people into thinking there is no (or little) point to OOP. It's misleading because most of the time, people end up making a program to do whatever specific job they are doing, and then move on. They only really begin to grasp the appeal of OOP when they do enough jobs to notice that hey, every single job I've been doing I've been having to write a login routine or xyz routine over and over again, so why not make a general framework...like...a function, and pass the info specific to the circumstance to it? And yes, even then that's fine and dandy, but the point of OOP is peace of mind. When you write a function, the point is that the code inside that function will be doing the same thing over and over again. The only way to be sure that when you call that function it will do what it is supposed to do every single time, is to enforce boundaries on it. Those boundaries is the fundamentals of scope. That's the point of scope: to ensure that complete control over what happens inside the function, stays with that function. So why can't you just continue to do that with a handful of functions and variables? Well, you can, but there's no piece of mind. Let's say you make a database handling script. You use several variables and several functions, and each one may or may not depend on one or more of each other. Well, if you leave out one of those functions, your system as a whole will bug or altogether break. You want them to be grouped together and stay that way. Some of them you may want to allow for people to alter or add on to, and some of them may be the "core" of your "system" that absolutely must not be changed, in order for the "system" to do what it's supposed to be doing. It's like changing a tire on a car. You can buy different kinds of tires, but the tire you buy has to connect with the same amount of nuts and bolts spaced the same way, in order for it to fit on the car, the rim has to be made out of material that can support the weight of the car, etc... if you do not enforce these things, the wheel could fall off. That's the point of the OOP paradigm: to ensure that your collection of functions and variables are being used the way they are supposed to be used, in order to keep the system from breaking. You can leave it up to the user to use the variables and functions properly, knowing how they are supposed to be used, or you can put them in a class that defines how they are supposed to be used. It boils down to packaging the parts up into a nice "interface" so that you or other people don't need to worry about what's going on inside. That's why things like microwaves have all their internal parts hooked up and wrapped up inside a case and you have buttons on the front to operate the microwave's internals within the scope of how they are intended to operate.
-
No, I did it right. The intention was to show what happens when you instantiate an object of a class that has a constructor, trying to use follow the rules of its parent class that has a constructor. No, you do not get a fatal error. You don't even get a warning or notice. php simply discards any passed arguments beyond what is defined in the function (or class method). If it requires no arguments and you pass 1+ they will simply be ignored. If it requires 1 argument and you do 2+, same thing. It only yells at you if you have less than what is required. TBH I'm not sure why this is. For instance, javascript will throw an error at you, saying that you are trying to pass extra arguments (it will still run though, so it's really like a warning/notice). Not really sure why this is not at least a warning or notice.
-
is there a problem with login?
.josh replied to beansandsausages's topic in PHPFreaks.com Website Feedback
In my experience, that usually happens when you have multiple accounts. -
I haven't had any need for a full blown IDE. I use html-kit. I like syntax highlighting, being able to have multiple files open at the same time, and built-in remote file editing. Anything else I don't need/use. But that's just me.
-
p.s.- Note though, that that is only true if the child class is not overriding the parent class's constructor. If the child class has its own constructor, then you would follow the rules for that constructor, not the parent's. So if you do this: class parentClass { function __construct ($greeting) { echo $greeting; } // end __construct } // end class parentClass class childClass extends parentClass { function __construct () { // example } // end __construct } // end class childClass // this works. childClass construct overrides parentClass construct // childClass construct requires no arguments to be passed to it $someObject = new childClass; // this also 'works' but does not do what you may think! // remember, childClass construct overwrites the parent class's constructor // so it's just like passing arguments to a regular function that doesn't // have any arguments declared $someObject = new childClass("hello");
-
Okay, to understand this, understand that php is not compiled, it is interpreted. The difference between compiled code and interpreted code is this: compiled code can be executed by itself, without the compiler. I can write a program in c++, compile it, and I can execute it on a machine that does not have the c++ compiler on it. Interpreted code needs the compiler to run. So I cannot write a php script and run it on a machine that doesn't have php installed on it. The reason why languages like c++ create a default constructor class is because the code is compiled into a stand alone program. Therefore it needs to know everything. It's the same reason why you can't just create variables on-the-fly in a compiled language (you have to declare them first, even their type). It needs those things made, and those boundaries set, because it doesn't have the compiler there to hold its hand telling it what to do when something goes awry. So in a way, compiled programs are standalone because they have a sort of mini-interpreter built into them. So when you don't have a constructor class in c++, a default one is made, but it is empty. It doesn't actually do anything. Since php code is interpreted, there's no need to create some empty constructor class as default, because it is just parsing the code and spitting out results as it comes. If you define a constructor in a parent class, a child class will inherit it. If the child class defines a constructor, the parent class's constructor will be overridden. If a child class does not define a constructor, it will treat the parent's constructor as its own. So if the parent class requires arguments to be passed, then you will have to pass arguments to the child class when you instantiate an object of that child class. Example: <?php class parentClass { function __construct ($greeting) { echo $greeting; } // end __construct } // end class parentClass class childClass extends parentClass { // nothing actually in this class except // for what is inherited from parentClass } // end class childClass // instantiating object from parent class $someObject = new parentClass; // error: missing argument $someObject = new parentClass("hello"); // correct /*** instantiating object from child class ****/ // even though there is no constructor in childClass, this will give you // the same error as in the first example above. $someObject = new childClass; // error: missing argument $someObject = new childClass("hello"); // correct ?>
-
The origin of my handle is an epic saga, and cannot possibly be contained in a single post. Yes, it is a pointer. IMO the problem with a lot of books and tutorials is that they tend to explain abstract things by using more abstract words, so most people only understand what they are saying if they already knew the topic in the first place. PHP is a loosely typed language. It does not require you to declare variables. it will not give you a fatal error if you don't, but it will give you a warning. If you don't see a warning from not declaring variables, it is because your php settings suppress it (or you suppressed it in the code somewhere). You do, however, have to declare a class property (a class variable), and trying to use a property that doesn't exist will give you a fatal error. I'm not 100% sure what you mean, so I'll try to answer this as I understand it. If I hit the nail on the head, awesome. If not, please clarify. Let's say you have a class and you want to make another class that extends that first class. The first class would be that second class's parent class, and that second class will be a child of the parent class. The child class inherits everything from the parent class, except for things specifically flagged not to be inherited (you do this by putting "private" in front of the property or method in the parent class). By default, everything is inherited, even the constructor, so when you create an object from the child class, it will call the parent class's constructor. If the parent class has a constructor, and you make a constructor class in your child class, the child's class will override the parent class's constructor (the same override happens if you name any property or function the same thing as something in the parent class). If you do not want this to happen - that is, if you want both the parent and child constructors to be executed, you need to call the parent's constructor class inside the child's constructor class. Newcomers to OOP find it large and scary and don't really know where to begin. Let me sum it up in one sentence for you: Classes add another layer of scope to the environment. The End. If you already understand how a functions work (noticing that a chunk of code is being reused over and over so you group it together, slap a label on it and just call it by name, passing/returning variables, variable scope, etc..) then you are 99% there as far as classes are concerned. Class properties are simply variables that operate within a class. Class methods are regular run of the mill functions that operate within a class. There are lots of different features and syntaxes and "permissions" for property/method accessibility that go along with it; it is a very robust upgrade to what functions offer, but it all still boils down to that single statement.
-
class someClass { // this is is a property in your class. A property is // a fancy way of saying "variable inside a class." var $someVar; // this is a method. A method is a fancy way of // saying function inside a class function foo () { // this will assign "something" to the $somevar property in your class // 'this' is an alias of the class name, so that php knows to assign it // to the property (variable) inside this class (someClass) $this->someVar = "something"; } // another method function bar () { // this will assign "something" to a variable local // only to this method. $somevar is a variable that only exists inside // this function, and is not related to the property $somevar in the class $someVar = "something"; } }
-
class something { function foo () { // do something } function bar () { $this->foo(); } }
-
How many posts needed to not be an irregular?
.josh replied to angelcool's topic in PHPFreaks.com Website Feedback
You don't actually expect people to read the stickies, do you? We only make them when we're bored and want to show each other our amazing typing skills. -
$TextUpload = stripslashes($_POST['text']); and p.s.- I notice in your code you have a textarea. Dunno if you're just doing that for testing purposes, but as I told you before, that preg_replace is only going to work if the entire string is the "..." so if you enter in for example blahblah "something" blahblah "blah" more blah that preg_replace is not going to go through and replace those quotes. I would suggest a regex pattern that could (mostly) do that, but I really have to wonder why you are trying to format your stuff before putting it into the database. Other than sanitizing, data should be stored in a database in as raw a format as possible, so that you don't restrict yourself when trying to use it later. If you format it a certain way, it would be okay for displaying that one way you had in mind, but if you want to display it some other way somewhere else, you're going to have to turn around and reformat it.
-
DO YOU EVER FEEL LIKE GIVING UP WITH YOUR WEBSITE?
.josh replied to give_up's topic in Miscellaneous
You offered your opinion based on your experiences. I offered mine. Getting hostile about differing opinions is not acceptable. I advise you to stop. -
Getting array from the php 'define' function using its arguments
.josh replied to jdneill's topic in Regex Help
I wouldn't call it a mistake if the data you provided didn't show a space before the comma, but I'm glad you nonetheless got it sorted it out. -
DO YOU EVER FEEL LIKE GIVING UP WITH YOUR WEBSITE?
.josh replied to give_up's topic in Miscellaneous
Sorry, but as someone who has been involved in several games, I find those numbers hard to believe. I think what is more likely is your friend the moderator puffed up the numbers, or else someone puffed it up to him. If they are somehow managing to pull that off, then more power to them, but that is not the norm. -
Getting array from the php 'define' function using its arguments
.josh replied to jdneill's topic in Regex Help
<?php $string = " define( 'CONTSTANT1', 'Text for constant one' ); define( 'CONTSTANT2', 'Text for constant two' ); define( 'CONTSTANT3', 'Text for constant three' ); define( 'CONTSTANT4', 4 ); "; preg_match_all("~define\(\s'(.*?)',\s'?(.*?)'?\s\);~s",$string,$matches); foreach($matches[1] as $k => $v) { $stringArray[$v] = $matches[2][$k]; } ?> There is a limitation to this: if the data that is supposed to be the key or value happens to contain something that matches the regex pattern, it's going to break the regex and return funky results. No matter how you try to break it down, I don't think there's really a way to prevent that from happening, other than storing your data differently to begin with. -
Okay if your entire string is "something" with start of quote at the beginning and end quote at the end of the string, you almost got the preg_replaces right. You messed up by putting the stuff inside brackets, which makes character classes; not going to really explain to you what that means as you probably don't care, point is, remove the brackets. The 2nd one only worked by happy coincidence. The unintended side effect just happened to match what you wanted. The preg_replaces would look like this: $TextUpload = preg_replace('^"','„',$TextUpload); // replace " at beginning of string $TextUpload = preg_replace('"$','”',$TextUpload); // replace " at end of string
-
DO YOU EVER FEEL LIKE GIVING UP WITH YOUR WEBSITE?
.josh replied to give_up's topic in Miscellaneous
pfft. If it's like virtually all of the other text based browser games, those numbers are grossly inflated. It's no secret that people make multiple accounts on games like those, in order to get ahead. -
Seems a bit bloated, but, here's my off the top of my head take <?php // example data...list and sorting would come from query $list = array('apple','angry','banana','carrot','fickle','8track','_blah','wtf','first','9ball','?something'); sort($list); // example loop...should use while loop for db data // foreach item in the list... foreach($list as $item) { // get first char and capitalize $currentItem = strtoupper(substr($item,0,1)); // if first letter is not alpha... if (preg_match('~[^a-z]~i',$currentItem)) { // if we haven't made # header... if ($nonAlpha == false) { // echo header echo "#<br />"; // set header bool to true $nonAlpha = true; } // end if to make # // else, if first letter alpha... } else { // if current first letter is not the same as previous one... if ($currentItem != $prevItem) // echo header echo "$currentItem<br />"; } // end else Alpha start // assign current first char to prevItem $prevItem = strtoupper(substr($item,0,1)); // echo current item echo "$item<br />"; } // end foreach item ?>
-
DO YOU EVER FEEL LIKE GIVING UP WITH YOUR WEBSITE?
.josh replied to give_up's topic in Miscellaneous
They are still holding on for dear life on social networking sites like myspace, but for the most part...yeah, that fad is pretty much over. -
DO YOU EVER FEEL LIKE GIVING UP WITH YOUR WEBSITE?
.josh replied to give_up's topic in Miscellaneous
Could be lots of reasons for that. Maybe you aren't making your site visible to potential players. Posting links on relevant boards/sites, etc... Maybe your game just sucks, and you need to sit down and do some major overhaul. Or maybe it's not that it sucks per se, but it's just another average, dime a dozen game, and you need to make it unique. Give people a reason to play yours instead of just picking a random game out of a hat. -
What is the best time to hold an online contest?
.josh replied to chmpdog's topic in Application Design
Well that depends on the contest. I wouldn't recommend starting a star-gazing contest in the middle of the day. -
yes, I want to eliminate 2 spaces into 1 - I dont use a ereg_replace Not really the point of this thread, but doing that str_replace would only replace two spaces with one. What happens if there's 3+ spaces? It would be more practical to do something like this: $TextUpload = preg_replace('~\s+~',' ',$TextUpload);
-
haha yeah man..that's nothing new. I've read about viruses and other attacks being done through images since I was knee high to a grasshopper. It personally hit home when I started using the GD library for image manipulation a couple years ago, when working through the random kinks and bugs to get the script working properly, I would often see the image data just dumped to the browser, instead of being rendered as an image. I quickly realized that if one were to inject html/js into the image data, a browser could possibly end up just dumping the data like that and possibly execute the injected code, or if the browser were to read the data trying to render it, it might just blindly render it as html/js instead of thinking hey wait a minute, I'm supposed to be rendering an image...what's this code doing in here?
-
Why is it a big deal? Having to validate user input is nothing new.
-
fwrite file_put_contents