I_Code Posted March 8, 2021 Share Posted March 8, 2021 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!! Quote Link to comment https://forums.phpfreaks.com/topic/312258-terminate-the-execution-of-a-script-in-php/ Share on other sites More sharing options...
requinix Posted March 8, 2021 Share Posted March 8, 2021 exit() can terminate all execution, yes. It is almost never appropriate to use. Quote Link to comment https://forums.phpfreaks.com/topic/312258-terminate-the-execution-of-a-script-in-php/#findComment-1584950 Share on other sites More sharing options...
requinix Posted March 8, 2021 Share Posted March 8, 2021 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312258-terminate-the-execution-of-a-script-in-php/#findComment-1584952 Share on other sites More sharing options...
I_Code Posted March 11, 2021 Author Share Posted March 11, 2021 Hey requinix, thank you so much! May I know what's really wrong with the resource i was following?. So that it would help me understand and switch. Quote Link to comment https://forums.phpfreaks.com/topic/312258-terminate-the-execution-of-a-script-in-php/#findComment-1585013 Share on other sites More sharing options...
requinix Posted March 11, 2021 Share Posted March 11, 2021 Sure. Here's some commentary on the questions and answers they give: Variables vs constants. Decent except they say constants are defined with define() when modern PHP should be using the "const" keyword. Sessions. They really gloss over what they are, and they almost suggest that it's done without using cookies. PEAR is irrelevant. Almost nobody uses it. 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. Partial case-sensitivity is right. Variable types is basically right but the graphic pointless. What it says about resources is close but not quite right. Variable name rules is right. 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. 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. PHP vs HTML. Basically right. They should not be mentioning @. Again, not something new PHP developers should be learning about. Parser. Why are they even mentioning this? There is only one "type" of array in PHP. Thinking that there are three types will only create confusion. Notices vs warnings vs fatals. Eh, fine. Traits. Also fine. Javascript vs PHP. Saying "PHP has the ability to generate Javascript variables" is dumb. They don't even mention the concept of AJAX. 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. Mentioning crypt() for hashing is incredibly bad. I threw out the whole article when I got to this point. include vs require. They do not "copy all the contents of a file". That's a terrible description of what they do. 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. Why the hell are they bothering with ASP.NET? "Escaping to PHP" is a weird way of saying what backslashes are for. Path traversal attacks are important, yeah, but beyond the scope of this article. Do not get security advice from "Top PHP Interview Questions" clickbait. Final vs not. Correct, but what is this about "creating an immutable class like String"? Creating a database in MySQL. This is silly. session_start/destroy. Fine. memcache is dead. (memcached is not) Talks about "different ways of handling MySQL result sets" using mysqli functions without even mentioning the more common PDO. The code for using cURL has smart quotes. Smart quotes. "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 Finally mentioning PDO. The article is just a series of FAQ questions in random order. GET vs POST. Decent, except where they try to say that POST is secure and GET is not. Type hinting explanation is... adequate. 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. Quote Link to comment https://forums.phpfreaks.com/topic/312258-terminate-the-execution-of-a-script-in-php/#findComment-1585026 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.