Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

php + Smarty looks like CGI

by Anonymous Monk
on May 17, 2003 at 18:02 UTC ( [id://258881]=perlmeditation: print w/replies, xml ) Need Help??

I've done lots of perl CGI programming but I thought I'd give php a whirl.

I started with a vendor supplied form that had php code and html all on one page. Quite a mess I thought, so I immediately used the Smarty template engine to bring some order to the party.

Then it hit me, that once you separate the php from the html, the php script could very well be a perl cgi script. They are invoked the same way from an html <form> tag. Yeah, I know how php is integrated into apache, and speed, etc.

One thing I really like about php is the support for sessions. I thought that was missing from perl until I went over to CPAN and found a CGI::Session library, that quite frankly, provides better support for sessions than php, unless I'm missing something. CGI::Session

For instance, I was on a php mailing list and a poster there wanted to know how to expire a session. Apparently in php there is no call similar to this in CGI::Session: $session->expire('+1M'); # expire after a month. Instead you have to save a timestamp as a session variable and then go test it yourself.

Plus there's like 4 functions to do what split() does. One handles only regex's, another doesn't, etc. What's up with that?

I'm just about paralyzed now, I can't work on my project any more because I don't see what php is buying me. The fun I was having with php is gone, vanished, dried up. Now I'm in questioning mode. Full of doubt. And that's why I've come to the Perl Monks.

I've read countless posts comparing php and perl. If you check out some of the php sites they want to rewrite the whole world in php (one guy even wants to replace cvs with a php hack). It feels like a purge, a re-writing of history. Friends have told me "greg, perl is old school. get with the future - learn php". :-)

Ok, there's a certain amount of humour in all this I'll admit, but I don't understand all the hype.

Replies are listed 'Best First'.
Re: php + Smarty looks like CGI
by crenz (Priest) on May 17, 2003 at 22:40 UTC

    I can't see any benefits that speak for PHP for myself, but clearly there's a lot of people out there that do. And I believe it doesn't have to do a lot of PHP being "better" than Perl, or, for that matter, vice versa.

    A lot of people comment, and I agree, on how they love Perl because it matches the way they think and solve problems so well. I guess it is only logical to conclude that there's a lot of people that find that PHP/Visual Basic/Java/C#/... match their way of solving problems well. They will find the problems you found with PHP insignificant, and instead will take issue with some things in Perl that never occured to you to think about.

    Of course, deep inside I admit to thinking that Perl, after all, is better :). However, I find that when dealing with people that don't want to dabble with Perl for whatever reasons, it is not my attitude that convinces them -- but rather the way I use Perl to get the job done. And of course, sometimes there's situations where you just have to let people not use Perl.

      As a newbie to both PHP and perl, I'd like to see a truly objective (Note: may not exist) comparison of the two. I think there must be areas where one has strengths over the other. If any such comparisn exists, though, I've yet to find it.
        I've written what I hope to be a fairly objective comparison of Perl and PHP in Re: Preaching Perl gospel to PHP converts.... But further to that here's a simple list of the various differences between the two languages

        Perl PHP
        Language features
        Lexical scoping and dynamic scoping Functions have unique scopes
        3 different contexts (scalar, list, void) No context types
        5 different sigils - $,@,%,&,* One sigil - $
        Regular expressions part of the language Regular expressions accessable through functions
        Data
        Scalars, Arrays, Hashes Scalars, Arrays/Hash duality
        Type-ignorant with roughly 3 types (string, number, reference) Type-ignorant with roughly 13 different types (see. is_ functions)
        Explicit references Optional explicit references
        Pass by value Implicit (i.e it should do the right thing)
        Functions
        Can be called with 3 different syntaxes Called with one syntax
        Anonymous functions part of the language Anonymous functions from create_function
        Can be referenced Symbolic calls
        Args implicitly aliased to @_ Named args
        Objects
        Created through blessing a reference Created through new Class
        Multiple Inheiritance Single Inheritance
        Class variables aren't standard Class variables part of the language

        This is by no means exhaustive or entirely accurate but should give you some ideas of the fundamental differences between the two languages.
        HTH

        _________
        broquaint

(jeffa) Re: php + Smarty looks like CGI
by jeffa (Bishop) on May 18, 2003 at 13:58 UTC
    I been using PHP fairly extensively, and i don't think it is any better then Perl. It is easier for newbies to get stuff up and running with PHP ... but is this a good thing? You can still write dangerous code with PHP, if you are not careful (allowing someone to open an arbitrary file is still a possibility).

    I can't remember who said this, but truth be told, PHP is NOT a programming language* ... it is a templating tool. I can understand how someone with little desire for hacking can gravitate so quickly and religiously to PHP. It's the path of least resistance. And as a good friend of mine sings, "the path of least resistance always leads you to the least everytime" ... PHP programmers who think they are clever because they don't have to learn any Perl are just kidding themselves.

    And for the record i don't mind working with PHP at all ... it can get a little frustrating at times, but it's heaps better than ASP! ;)

    * broquaint reminded me that this is simply not true, he adds "[PHP] is a fully fledged language, and with the advent of php5 it might even become a respectable language."

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: php + Smarty looks like CGI
by arthas (Hermit) on May 18, 2003 at 18:11 UTC
    I used PHP for some (small) projects, while I always used PErl for the others. Now I'm back to Perl for every web project I do.

    In my opinion, PHP is agood and easy to use tool to create dynamic web pages: I wouldn't define it a programming language (but, then, I can be burnt for this ;-)).

    If you know Perl, stay with it.

    Michele.
Re: php + Smarty looks like CGI
by Anonymous Monk on May 19, 2003 at 17:49 UTC
    I earn my daily bread with PHP. I'm just learning Perl, which I find fairly easy because PHP is, after all, a mix of several languages including Perl (just as Perl is a mix of others (awk, sed, shell)).

    I'll say this in favor of Perl: I've found lots of stuff on which I told myself: "gee, I can't do this with PHP". What I don't like about Perl, and I'm sure you've heard this before, is its syntax. It's too easy and too tempting to obfuscate things, which is a double-edged sword.
    With PHP (and even more with Python) you don't have such, uh, flexibility to overcomplicate things, or do them "my way". Which is a Good Thing(tm) for big projects, for consistency, for team work. Yes, you can do the same with Perl if you enforce coding standards, but it's somehow a different and more complicated level of standards because it involves syntax under a different context.

    PHP was designed for dynamic web pages in mind and, in my little personal opinion, it does a great job. Oh, and I find it stupid too the movement of "wow, let's do everything in PHP now" (like GTK apps or webservers). I think Perl has more chances for that. Ignore those.

    Ah, and you can control the session cookie with PHP, it's possible to control the expiration with session_set_cookie_params().

    jaime.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://258881]
Approved by gmax
Front-paged by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found