Things in php that made you go WHOA!
Moderator: General Moderators
Things in php that made you go WHOA!
I am just discovering things in php that I never even knew about... like output buffering... things that should have been explained somewhere along the line in my 3 or 4 years of off and on php-learning. In this thread, I would like for everybody to just sort of point out a few things that are very useful, but often are over-looked by new-comers or lazy php programmers like myself. Then I would like for you to explain their usage, and maybe even give some examples. Begin!

Found an interesting article on output buffering that others may find useful.
http://www.zend.com/zend/art/buffering.php
I too have been missing out on this functionality, not so much laziness as blind ignorance.
http://www.zend.com/zend/art/buffering.php
I too have been missing out on this functionality, not so much laziness as blind ignorance.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
One technique I use sometimes is to create a Monostate object by binding a varaible to a key in one of the PHP SuperGlobals. For example, if I want a queue of notifications, I might bind an attribute to a key in the $_SESSION array and then any instance of that class can add to, or display and clear, the queue.
Here was something I wrote up on that technique: http://blog.casey-sweat.us/?p=18
Here was something I wrote up on that technique: http://blog.casey-sweat.us/?p=18
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
I just learned that is a perfectly valid short cut to I had no idea.
Code: Select all
<?=$var?>Code: Select all
<?php echo $var; ?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
What happens when short tags arn't enabled? I've heard several horror stories when porting large projects to a new host to find out their code no longer works.Charles256 wrote:I just learned thatis a perfectly valid short cut toCode: Select all
<?=$var?>I had no idea.Code: Select all
<?php echo $var; ?>
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
This may sound really newbie-ish, but my favorite feature of PHP has been the array functions. When I learned what an array was and how to use them properly, my code development eyes were opened.
Now it is more the object oriented approach that can be taken when developing (that whole passing by reference thing is pretty cool too). But really, everyday there is something that I run across that makes me say "Dude, this is the coolest language!".
Now it is more the object oriented approach that can be taken when developing (that whole passing by reference thing is pretty cool too). But really, everyday there is something that I run across that makes me say "Dude, this is the coolest language!".
This isn't really php, but linux has brought many moments like that. Especially when you know a scripting language, which isn't really the best CLI language, but still, if I need a linux applet, I can just whip something up in php, 10 minutes later, I have a script that does whatever I want - from rotating background images, to talking to microcontrollers. The whole thing is amazing to me.