
kevint
New Members-
Posts
6 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Male
-
Location
Canada
kevint's Achievements

Newbie (1/5)
0
Reputation
-
I haven't been writing PHP all that long; I like to look at a lot of code to learn from it. So, I'm noticing lots of use of the "&" thing to pass references, in places where I can't understand the need for it. For example, this (from an example snip of code for a PEAR extension): <?php $r =& new XML_RSS("test.rss"); ?> Why is the & needed here? How does anything benefit from this? I understand that the & can be used to create references, but I am not sure why this is ever really a useful thing to do (rather than just using the variable itself, instead of the reference). Can someone possibly share with me how, and why, they tend to use this feature? In general, that is; and specifically, in the example above, does anyone know why it was done this way (like it also is in so much other code that I see)? Thanks in advance for any replies; cheers.
-
So, if I define a class, and do not give it a constructor: class ExampleClass { private $name; public function getName() { return $this->name; } } Then what happens if I call it and pass it a parameter? $blah = new ExampleClass("myName"); Will doing this still load it into the $name variable (by the "default constructor")? I'm guessing not. So, in general, when making a class, ALWAYS define a constructor? Would you guys agree that that is generally true? Another part that I find very weird is: why do you need the construct function at all? Wouldn't it work better if you could define the class like this: class MyClass ($one, $two, $three) { public function echoOne { echo $one; } } $blah = new MyClass(1,2,3); $blah.echoOne; //outputs "1"; Where the "constructor" is part of the definition of the class, instead of a function within it (like the way you define functions!) ?? There must be a reason why it is not done this way. Just curious, too: I was looking back over the replies to this post. I have seen this done lots of times as well and never quite undertood: foreach($GLOBALS as $key => $val) When you do this, are $key and $val predefined "pseudo variables" as well, that you can use to build the associative array? Or could I use foreach($GLOBALS as $fling => $poo) and get the same result? Thanks again
-
The info so far is very helpful! And thank you also for the link to the manual. I wasn't sure where to find it in there, and searching produced all kinds of results. Just another question: (Based on the code from Nightslyr): class ExampleClass { private $name; private $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } public function getName() { return $this->name; } public function getAge() { return $this->age; } } Does the __construct() function always take care of assigning whatever variables are passed to a class when an instance of it is created? What if I created a new ExampleClass, but passed it three values, like: $blah = new ExampleClass("one",2,"thirdValue"); What would happen to the third value? Since nothing deals with it in the __construct() function. Also, how does the __construct() function know what $this->name is, so that it can assign it to private variable $name? You pass two values to the class when you create a new instance of it, but how does it know that $this->name is the first value you pass, and $this->age is the second? If I did pass it three values, how would I load the third value into a private variable called $third?
-
To a lot of the people here, this is going to be a really stupid question. I know this, because based on the amount of code I have seen that uses the technique in question, it must be quite prolific. However, I have not been able to find a good explanation of the theory. Question: What exactly does the "this" variable (is it even a variable?) do, in PHP or any other language (such as JavaScript, where I see it even more frequently)? For example, this bit of JavaScript from a tutorial I was checking out on IBM's dev site: <select id="elFeedList" onchange="loadFeed( this.options[this.selectedIndex].value )"> </select> Or, more appropriately (since this is a PHP form), this code (from the same site): private function __construct() { $dsn = 'mysql://root:password@localhost/rss'; $this->_handle =& DB::Connect( $dsn, array() ); } I constantly see a variablish thing called $this in PHP code I check out, and I am not sure what exactly it does. And I always see stuff like "this.something" in JS. I haven't been able to find a good explanation. Google returns plenty of pages that have the word "this" in them, but nothing dealing with what I am looking for. Maybe I am searching wrong; there must be some kind of name for this feature. I have no idea what it is though... Help?
-
Thanks for the quick replies -- I just posted this last night. Just thought I could maybe re-phrase the question. So, when you want to learn a [programming/ scripting/ whatever] language, you can go online for tutorials. You will always find the same stuff, taking you through outputting text and then introducing the idea of arrays, moving on to functions, etc. Shortly thereafter it stops. There is a plethora of "beginner" tutorials for everything. After that you tend to move out of the "tutorial" mode and get into more specific problems; you can find answers to these in forums and the like, but you only tend to get there by searching for that problem specifically. I have no idea what to search for, where to begin, etc. I'm not exactly looking to JUST become a PHP developer. Like ignace said, you often wear many hats, and I like that. I know Photoshop better than I know any language. Between ages 16-18 I worked for a photographer doing all of his digital imaging. It didn't pay enough to keep the job (he hired me BECAUSE I was willing to do it on the cheap, instead of hiring someone with a degree). But I had the opportunity to learn the program forward and backward. I just love the web, and the next step I want to take is becoming really good at PHP. From what I can tell, there is a future in the language. I want to learn lots of other stuff too, like Javascript. But this is the PHP forum, so that's all I'm asking about. So here is the new question: How did any of you guys go from the beginner PHP tutorials to being good enough with the language to work on higher end, more professional projects using PHP? How were you able to make the jump from the starter material, which you can learn on any number of sites, to the advanced stuff? What projects did you take on, and how did you find them, that not only showed you WHAT you had to learn to get to the next level, but allowed you to implement that knowledge and thereby gain a more abstract, conceptual understanding of it (as opposed to the concrete-style "this is how you do it" of tutorial websites). Hope that helps. Sometimes it's hard to find the right words. If you're super good at PHP; like, you could write core code for WordPress or Drupal or something like that; I want to be like you. I'm sure I'll get there eventually, by hacking my way through. But I find it hard to see what route I should take to get to the next level. (Which is why this post is here, looking for pointers from people who've done it).
-
Hey guys So, I'm new to this website. Actually, today I intended to sign up for the forums on php.net (which I just assumed would exist) and post something like this. Their mailing list structure didn't appeal to me; I wanted a forum. I'm not sure that this category is the right place for this post, but I couldn't find a cat. that seemed 100% appropriate. So, here goes: I'm a big web enthusiast, and have been for quite a long time. I do not work in the web industry. I am aware of more technologies/ concepts than ones I can actually implement (example, I know what Rails and AJAX are, but have never used either. I understand what people mean by 'object-oriented', but I'm not an expert programmer in any language). So, that's a bit about me. I want to do this for a living, eventually. I've been dabbling since I was 8 or 9 (I'm 24 btw), but never made any decisions until now (I have lots of other interests, too; probably, like you guys do as well). Here is my current situation, and the problem that follows from it: It will be a little while before I can actually switch jobs and go back to school for this (maybe a year or two). So for now I am trying to build up my skills at home. I read voraciously about all of it. But I find you need to actually DO stuff (produce) to transfer all the theory you learn by reading into real, usable skills. I knew a bit of php (and when I say a bit, I mean I knew how to make Hello World) years ago, and I always liked the idea of it. So I decided I would learn that. And MySQL. We have a lot of computers where I work, and a lot of times they need to be replaced, upgraded, etc. The shocking thing was, there was no central record of all that we had, or where any of it was located within the organization, etc. So I undertook this project at home as my way of learning PHP and MySQL (not really to help out my employer, but that was a side-effect and doesn't hurt my image there at all). I read a lot, and made a good little web app. I read up on relational database design, and then used MySQLWorkbench to draw one up for my purposes, and exported the code. I installed MySQL to run locally on my laptop (Macbook Pro). I installed an updated PHP, too. I had sample chapters from a book from Sitepoint.com called 'Build Your Own Database Driven Web Site Using PHP and MySQL' (by Kevin Yank). I liked what I had, so I bought the whole book and read it. Using that and a bunch of Googling, I built the web app. I'm proud of it. I am SURE that I used more code than necessary, defined more variables than necessary, etc. But it WORKS. And it's built in a modular fashion, using lots of includes and reusing lots of code, instead of having one big page with everything in it. What I have is a relational database (that uses foreign key constraints, even; make fun of me if that's not supposed to be something to be proud of) containing all of our IT assets at work. I inventoried them all myself and put them into this thing. You can use the web app to search through the table (filter by any of the columns, like location, model, etc.). You can sort the table by clicking on a column title to sort the whole thing in ascending order of that column (by table, here, I mean the one displayed on the web page. The MySQL database for it is relational, and has 6 or 7 tables. Example, the master table has an asset number for a computer and a location id number. The location table relates that location id number to a location name like "front office"). You can add stuff to it with another form. You can modify stuff, delete stuff, etc. I made this using PHP, connecting to my MySQL database, and outputting HTML. And then I styled it all up pretty using CSS and graphics I made in Photoshop. (I wrote it all in an OS X web dev app called Coda - http://www.panic.com/coda/). So, hey! I'm proud of it. I started out knowing HTML and CSS, and how to make Hello World appear in PHP. I knew nothing about databases. I knew what I wanted to make, I learned what I had to, and I made it. And it works (well). So now, here's the thing: I really want to continue with this!!! I LOVED DOING IT! But that database web app that I made was pretty much all I could think of to make. My current job doesn't have many opportunities like this. It's not an IT industry, we just have lots of computers, and they weren't kept track of. Now they are. That's pretty much it, for that. I am hoping that some of you gents (or ladies) can point me in the right direction. I could (and do) read about more advanced topics than the ones I implemented to make my app. But I have no where to apply this knowledge. Are there some open source projects I can become part of, that any of you know of (I mean something smaller in scale than, say, WordPress, which is very advanced)? How did all of you do it (find ways to apply the advanced theory, and thereby turn it into a skill)? Are any of you guys also developers with jobs not related to PHP? Or maybe you used to have such a job? How did you make the jump from the basic stuff (which is what I consider the app I made to be) to the advanced? The thing is: the basic stuff (talking to the database, displaying the info on your page as HTML) has a lot more common applications than the more advanced things you can do with the language. This might seem nebulous. I'm not sure how to ask what I want to ask. I'm looking for a way that I can get more into this community, and learn to be a real PHP developer. Like an app in development that I can be part of. I know, there are tons of open source PHP web apps out there, but the ones I have looked at have lots of code that I don't grok at all. And if I were to write something (like an extension) for one of them, I'm not sure where to start. I'm re reading this post and even to me it sounds like, "What exactly is this guy asking?". Basically: I can now make basic stuff using PHP and MySQL. What is the best way to get into more advanced stuff? In a way that I can do more than just read about it. A way that I can read the theory and then have something to apply it to, so that it becomes part of my skills set. Any answers are appreciated. Move my topic if it's in the wrong place, I wasn't sure which category fit this most. I want to learn to design more advanced web applications, so I put it here. Thanks for any help guys! Cheers, - Kevin (in Canada).