[PHP] Howdy (new in here)
Hi everyone! I'm just starting out with PHP so I'm looking for a good place to ask some questions, have my code critiqued (read: visciously ripped apart), and generally BS about PHP and programming in general (if that's OK). I know that PHP sometimes has a reputation for having (some) lousy developers, and I'd like to avoid becoming one of those people. To that end, I've subscribed here because I've always found mailing lists to have much higher-quality discourse than the average online foum. Looking forward to participating! - BW P.S, The rules page on the web (http://us2.php.net/reST/php-src/README.MAILINGLIST_RULES) is currently broken, but this one works: http://us2.php.net/reST/php-src/trunk_README.MAILINGLIST_RULES. Just a heads up to whoever is in charge of that. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Rate my (really) simple template class
So I decided to write a template class in order to get myself going on learning PHP. Of course I wrote the simplest thing possible: class Template { protected $template; protected $vars; public function __construct($template) { $this->template = $template; } public function __set($name, $value) { $this->vars[$name] = $value; } public function __get($name) { return $this->vars[$name]; } public function __toString() { ob_start(); eval('?>' . $this->template); return ob_get_clean(); } } Which you can use, quite simply like this: $tpl = new Template(file_get_contents('index.tpl.php')); $tpl->title = 'Here\'s the title'; $tpl->text = 'Blah blah blah...'; echo $tpl; I have a few questions though. - First, I'm storing the template as an actual string, instead of just a path to a template file, which means I'm using eval() instead of require() in my __toString(). My thinking was that this would avoid reading the template file twice in the case that __toString() gets called multiple times. But will PHP handle this automagically if I do in fact decide to store a path to a file, and call require() instead? - Secondly, I noticed that in the constructor, it's not necessary to initialize $vars to an empty array, and I haven't done so. I guess PHP automatically initializes it the first time I set one of its elements to a value. Is this okay, or is there a better way in the name of best practices? - Finally, I'd like to be able to limit what things can be accessed from the scope of the template file. As it stands, if you have a function named blowUpTheComputer() or a gobal variable called $dontTouchThis, a template author can easily cause trouble. They can also access any methods and properties of the Template class. How would you go about restricting this? Thanks a lot! - BW -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Howdy (new in here)
On Tue, Feb 15, 2011 at 12:52 PM, tedd wrote: > At 11:37 AM -0600 2/15/11, Nicholas Kell wrote: >> >> On Feb 15, 2011, at 10:51 AM, tedd wrote: >> > At 8:26 PM -0500 2/14/11, Brian Waters wrote: >> >> (if that's OK). I know that PHP sometimes has a reputation for having >> >> (some) lousy developers, and I'd like to avoid becoming one of those >> > >> > We don't agree that PHP has a reputation of having some lousy >> developers -- because that's simply not true. >> >> Humm I seem to agree with the OP. But, that being said, unlike most >> language fanboys PHP'ers usually fully admit it. > > > I guess that we run in different worlds. Most of the PHP programmers I know > are very good. I didn't mean to suggest anything. Nor do I necessarily subscribe to the idea (that PHP has some lousy developers). It's just something I've heard bouncing around - probably on those noisy internet forums. - BW P.S: On Tue, Feb 15, 2011 at 11:51 AM, tedd wrote: > PS: We seldom point out spelling errors, but it's good to review what you > post. Remember, what you post will be public for generations to come. I'm aware that I misspelled "viciously" in my original post but was too lazy to rectify the situation. P.P.S, Apologies for backchanneling tedd there; I'm used to mailing lists with a default Reply-To: t...@mailinglist.com header. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Howdy (new in here)
On Tue, Feb 15, 2011 at 3:37 PM, tedd wrote: > So, I took a *weekend* and programmed about 90 percent of application in > FutureBasic. I then created a shell application and forwarded it to the > client. > > After receiving the application, the client said "Yes, this is exactly what > I want -- except I want it in C++". Of course, that's a ridiculous reason to choose one language over another. But to augment what you're saying, sometimes certain languages are chosen because of the availability of libraries and tools, and, more importantly, because of the availability of skilled programmers. That's especially important if a client has to expand and modify a solution in the future. - BW PS, Once again, tedd, apologies for backchanneling you... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Rate my (really) simple template class
On Mon, Feb 14, 2011 at 11:49 PM, Paul M Foster wrote: > Advice: don't use eval() this way. It's slow and dangerous. Could you elaborate, or provide a link? > ...read in the file and pass it to you on the stack, which is > really an abuse of the stack if you can avoid it. Interesting. I'm used to statically-typed languages. Normally I never would have passed a large structure like that on the stack. But then again, in those languages, large structures are usually passed by reference, by default. In C, the only way to pass a string or array by value is to wrap it in a struct, and in Java, objects are passed by reference (if I recall correctly). Guess that's something to get used to. - BW -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] chat facebook
2011/2/19 fakessh @ : > anyone have a recipe for it on facebook chat a recipe for what? > and I request a second thing > how to install PHP API you're going to have to be more specific than that. - BW -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php