Jump to content

Terminate the execution of a script in PHP


Recommended Posts

Hello all, newbie here just trying to understand PHP and other languages. As a basic, i understood that exit() function is used to stop something. But, was wondering if below code is right to terminate something. Ref - InterviewBit

<?php
$site = "https://abcdefghijk.com//";
fopen($site,"r")
or exit("Unable to connect to $site");
?>

TIA!!

Link to post
Share on other sites

Also, that article you linked is absolutely terrible. Stop using that site, and I'm also going to ask you not to link to it in the future.

  • Great Answer 1
Link to post
Share on other sites

Sure. Here's some commentary on the questions and answers they give:

  1. Variables vs constants. Decent except they say constants are defined with define() when modern PHP should be using the "const" keyword.
  2. Sessions. They really gloss over what they are, and they almost suggest that it's done without using cookies.
  3. PEAR is irrelevant. Almost nobody uses it.
  4. Variable variables should not even be mentioned. It's bad to use them at all. And saying things like "reference variable" and "stores data about the variable" is not right.
  5. Partial case-sensitivity is right.
  6. Variable types is basically right but the graphic pointless. What it says about resources is close but not quite right.
  7. Variable name rules is right.
  8. echo vs print. I hate that they say print is slower. Even if technically true, that is not the kind of optimization that new PHP developers should be concerned about.
  9. Oh boy, the disadvantages of PHP:
    • "Not suitable for giant web apps". Wrong.
    • "Open source is not secure". Wrong.
    • "Changing the core behavior of online apps isn't allowed". I don't know what this is trying to say but I'm pretty sure it's wrong.
    • "Using features causes poor performance". Wrong.
    • "Poor error handling". Wrong.
    • "Lacks debugging tools". Wrong.
  10. PHP vs HTML. Basically right.
  11. They should not be mentioning @. Again, not something new PHP developers should be learning about.
  12. Parser. Why are they even mentioning this?
  13. There is only one "type" of array in PHP. Thinking that there are three types will only create confusion.
  14. Notices vs warnings vs fatals. Eh, fine.
  15. Traits. Also fine.
  16. Javascript vs PHP. Saying "PHP has the ability to generate Javascript variables" is dumb. They don't even mention the concept of AJAX.
  17. foreach. I can't tell why this is in here. Why aren't they mentioning all the other loop types? Why not also mention if and switch and other constructs? This doesn't fit.
  18. Mentioning crypt() for hashing is incredibly bad. I threw out the whole article when I got to this point.
  19. include vs require. They do not "copy all the contents of a file". That's a terrible description of what they do.
  20. Poor description of cookies. Nothing is "installed", they are not just about "storing data about the user", cookies are always and necessarily "URL particular", and the comments about cookie limits seem to be lifted from a StackOverflow thread from 11 years ago.
  21. Why the hell are they bothering with ASP.NET?
  22. "Escaping to PHP" is a weird way of saying what backslashes are for.
  23. Path traversal attacks are important, yeah, but beyond the scope of this article. Do not get security advice from "Top PHP Interview Questions" clickbait.
  24. Final vs not. Correct, but what is this about "creating an immutable class like String"?
  25. Creating a database in MySQL. This is silly.
  26. session_start/destroy. Fine.
  27. memcache is dead. (memcached is not)
  28. Talks about "different ways of handling MySQL result sets" using mysqli functions without even mentioning the more common PDO.
  29. The code for using cURL has smart quotes. Smart quotes.
  30. "How to create an API in PHP" does not belong here. They are trying to give a precise answer with database tables and code and someone is going to try to copy it. Problems:
    • Using latin1 charset
    • Using procedural mysqli
    • Using root as the database user
    • Using the "connect or die" approach to error handling
    • SQL injection
    • Defining a function inside a (MVC-style) view
  31. Finally mentioning PDO. The article is just a series of FAQ questions in random order.
  32. GET vs POST. Decent, except where they try to say that POST is secure and GET is not.
  33. Type hinting explanation is... adequate.
  34. Yes, exit() can abort a script, but it should not be used for regular error handling.

Finally, the quiz at the bottom asks questions that the article does not have the answers to.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.