addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupsimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1outlookpersonJoin Group on CardStartprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Re: [php-49] Is it bad practice to die 'inside' a class?

From: Jennifer T.
Sent on: Tuesday, September 15, 2009 12:38 PM
Certainly a better practice would be to return the actual of the login page and then do your redirect.  As for php's garbage collection, in theory it has automatic garbage collection and die should release any resources.  With this said in practice any vars assigned are held almost as markers so that even though the space is "free" you will sometimes get memory leaks until you expressly unset your vars or fill the same var name with something else. (Hope that makes sense)
 
Finally, in your example why wouldn't you return a page name, append the php and then include a template file.  Certainly a lot more reusable.  Would also allow you to use a db in the future and pull an array from there or completely customize/co-brand a page without a rewrite.  Just a thought.
 
Jen

Sent: Tuesday, September 15,[masked]:23 PM
Subject: [php-49] Is it bad practice to die 'inside' a class?

Not sure if I can word this well, so please ask for clarification as needed...

Hypothetical example of the concept (that is, I'm not looking for a better way to do this particular task, just using it as a simplified example):

MainPage.php
   <? php
   include ('theClass.php');
   $newUser = new theClass();
   $newUser->checkIP;
   echo "Welcome...";
   ...
   ?>

theClass.php
   ...                   // setup-stuff
   function chekIP() {
        if ($_SERVER['REMOTE_ADDR'] != '[masked]') {
                include ('aDifferentLoginPage.php');            //  THIS LINE!!
                die();
        }
    }


Roughly, if the user is not at[masked], then they are bounced out to a different page BY THE CLASS!!

1) Is this a bad idea or is it okay practice?
2) does this lead to memory-leak or other wasted RAM/processing issues?


David





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by David Malouf ([address removed]) from The Seattle PHP Meetup Group.
To learn more about David Malouf, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA

Our Sponsors

  • TUNE

    Meeting space and food

  • PluralSight

    PluralSight subscriptions for developer training

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy