1

I want to know if sending huge records to another php file functions cost more than to create functions in a current php file?

For example, in my current php file upload.php I have two type of arrays: $result1 and $result2, each with lots of records and I want to upload these records to my database with functions name upload_type1 and upload__type2.

Is it better to:

  1. Create these functions in my current file?
  2. Create these functions in a different file like databaseupload.php, and then send the $result array to databaseupload.php to have cleaner code?

Does the second way cost more?

I want to know what way is the better programming way. Thanks for your help!

MR.masoud
  • 137
  • 11
  • You could simply pass your vars by [reference](http://php.net/manual/en/language.references.pass.php) to the processing function – Mat Dec 18 '15 at 18:14
  • my question is about time cost is passing data through files take cost or not ? – MR.masoud Dec 18 '15 at 18:26
  • Tell us more details. How would you transfer the data between the 2 PHP files? BTW, nothing is faster than using a local var (or a reference), in the same PHP file or in 2 PHP files (using include / require) – Mat Dec 18 '15 at 18:52
  • is sending a data to a function (function($data)) that is in other php file and included in ur currnet file send a copy of ur data to second php file and duplicate ur data? if its true does it cost so much ? – MR.masoud Dec 18 '15 at 19:33
  • Possible duplicate of [What's the performance cost of "include" in PHP?](http://stackoverflow.com/questions/4890825/whats-the-performance-cost-of-include-in-php) – Ali Akbar Azizi Dec 18 '15 at 20:37

1 Answers1

1

Generally its so subjective but for two simple function there is not much difference to implement them inside or separate them in different file if you are concerning about overhead in your app. you can find more details and statistic here.

But having clean code is much more effective, I believe.

You'd better follow famous design patterns and SRP to know where and how create classes and functions.

Community
  • 1
  • 1
‌‌R‌‌‌.
  • 2,818
  • 26
  • 37
  • is sending a data to a function (function($data)) that is in other php file and included in ur currnet file send a copy of ur data to second php file and duplicate ur data? if its true does it cost so much ? – MR.masoud Dec 18 '15 at 19:33
  • @MR.masoud when it comes to passing data to a function, as long as you have access to that function, there is no difference where is located that function physically because that function has already loaded in memory. – ‌‌R‌‌‌. Dec 19 '15 at 17:59