PHP - exit or return which is better

0 votes

Case I:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   echo json_encode( $results );
   exit();
}

Case II:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   exit( json_encode( $results ) );
}

Case III:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   return( json_encode( $results ) );
}

In the PHP script, if the $fileSize variable is larger than 100, I stop the script;

Which of the three (3) options above is the best?

Jun 23, 2022 in PHP by narikkadan
• 63,420 points
413 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
0 answers

file_get_contents("php://input") or $HTTP_RAW_POST_DATA, which one is better to get the body of JSON request?

The file_get_contents("php://input") or $HTTP_RAW_POST_DATA - which one ...READ MORE

Jun 23, 2022 in PHP by narikkadan
• 63,420 points
900 views
0 votes
1 answer

How to check if php session is already started or not?

Hello kartik, Use session_id(), it returns an empty string ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,880 points
5,118 views
0 votes
1 answer

In PHP, how to detect the execution is from CLI mode or through browser ?

Hello @kartik, Use the php_sapi_name() function. if (php_sapi_name() == "cli") { ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,880 points
1,083 views
0 votes
1 answer

How to know which php.ini is used?

Hello @kartik, ou can use php_ini_loaded_file() Taken from php.net: $inipath = ...READ MORE

answered Oct 30, 2020 in PHP by Niroj
• 82,880 points
1,217 views
0 votes
1 answer

How to check if memcache or memcached is installed for PHP?

Hii, You can look at phpinfo() or check ...READ MORE

answered Nov 6, 2020 in PHP by Niroj
• 82,880 points
4,286 views
0 votes
0 answers

PHP is not recognized as an internal or external command in command prompt

I am getting this error when I ...READ MORE

May 7, 2022 in PHP by narikkadan
• 63,420 points
1,877 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,185 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
10,957 views
0 votes
1 answer

Failure uploading Image on AmazonS3 with PHP SDK

Try this, I took it out from ...READ MORE

answered May 4, 2018 in AWS by Cloud gunner
• 4,670 points
3,737 views
0 votes
1 answer

Trying to call AWS API via PHP

Try using AWS SDK for PHP, Link ...READ MORE

answered Jun 6, 2018 in AWS by Cloud gunner
• 4,670 points
1,480 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP