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

From: David M.
Sent on: Tuesday, September 15, 2009 4:33 PM
So let's say that I want to run this exact same 'check' on every page and all the 'check' does is check the IP and, if not to my liking, sends the user somewhere else.

That is, the ONE and ONLY thing this class does is 'check' and send the user elsewhere if the IP is wrong.

Would I be better off entering the world of Exceptions or perhaps simply include() the 'checkIP' function (no class, no OOP) at the beginning of each page?


Thanks for all the chiming in - I'm learning a TON about not only this scenario but other stuff (like the exceedingly large number of potential applications for try/catch ),

David





On Tue, Sep 15, 2009 at 3:05 PM, Ariz Jacinto <[address removed]> wrote:
Hi David,

Yup, it is a bad idea. First and foremost you need to define the scope of the class. Maybe all the class method need to do is return the corresponding boolean value if the remote ip address is allowed or not. So if the return value is false, then run die() or do a redirect at the _controller_.

if ($newUser->isIPAllowed()===false){
�� //redirect or display an error page

}



On Tue, Sep 15, 2009 at 12:23 PM, David Malouf <[address removed]> wrote:
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





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Ariz Jacinto ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Ariz Jacinto, 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

  • Siteground

    Information coming Soon

  • 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

People in this
Meetup are also in:

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