Things in php that made you go WHOA!

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Things in php that made you go WHOA!

Post by Luke »

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! :D :D
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post by bmcewan »

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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Although it's not that amazing...

cURL() is awesome in my opinion. I had never heard of such a thing before that (ya I was a n00b but still!) and it just blew my mind that you could be a user without being there. That made me go wow.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

The taken-for-granted PHP sessions made my day a long time back when starting. Ah, the good old days...:)

Currently, I think cURL is the coolest of them all. I haven't used it a lot so I'll be taking a time out at some stage to learn more about it in detail...
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

Probably regular expressions fit somewhere in that list, though in PHP they feel a bit like second class citizens when compared with Perl or Ruby.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

These are all great... how about some concepts? Anybody have any php design techniques they found particularly interesting?
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

I just learned that

Code: Select all

<?=$var?>
is a perfectly valid short cut to

Code: Select all

<?php echo $var; ?>
I had no idea.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Charles256 wrote:I just learned that

Code: Select all

<?=$var?>
is a perfectly valid short cut to

Code: Select all

<?php echo $var; ?>
I had no idea.
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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Can I shoot him? Please? :)

You should try stick with the longer tag form - it's more portable. The use of short_tags option in PHP is optional, so it's not supported on all hosts.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

There's no need for violence... let's just stay on topic :)
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

for the record, it wasn't my code. i always use the long form. it was in code i was working on. so bite me :-D. now, back on topic.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Object Oriented Programming and design patterns.. 8)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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!".
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

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.
Post Reply