August 10, 201412 yr Have a simple question If a file is included within a function but the function is not called will the file be included in this example below will test.php be complied by the server since it is not called.. function sergio (){ include ('index.php'); } function sergio2 (){ include ('test.php'); } echo sergio(); Edited August 22, 201412 yr by rallport PLEASE USE CODE TAGS!
August 10, 201412 yr Just my guess, forgive me if I'm wrong as I'm not really in to back-end... However, surely if the function isn't being called'd it won't compile it? Also, do you need the echo there?
August 11, 201412 yr Author <?php function sergio (){ return 'something'; } function sergio2 (){ echo 'Something'; } sergio2(); sergio(); depends if you use return or echo In the above example you will not get an echo from sergio(); I done research and try to conduct a tests. And yes it would appear that it doesnt.. but i wanted to make triple sure, before i undertook a project with two 5000 line function files. Maybe there is a better way of then the includes within a function Edited August 22, 201412 yr by rallport PLEASE USE CODE TAGS
August 17, 201412 yr Author This is just a terrible idea in general. Never do this. And the reason why? and whats the alternative you recommend? Edited August 17, 201412 yr by sergRamalli
August 17, 201412 yr Author I was a new developer on a project, and convention were not followed after 3 months i got them round to my way of thinking which is OOD.I get that classes are the way forward but as you rightly observed its two 5000 line files, The code is so hard to follow and any changes seems to error the whole site... Rebuilding is not option, as my boss doesn't want this... so i planned out stages to the process. First the includes way im asking about now, then slowing moving towards OOD, OOP and MVC, with time.. So ..to make this 5000 file more manageable, then to comment and understand each line, install conventions, design the new program and implement OOD, But think this needs to done, while the site is live and features are being added.. this include way is my only option as i can see Edited August 17, 201412 yr by sergRamalli
August 25, 201412 yr Author Firstly, please use code tags in the future For your 5000 line function/file, well that's your own problem. It represents some god awful development. Why onearth you can't split that up into manageable/reuseable classes is beyond me. As developers, huge chunks of unmanageable code is exactyl what everyone is trying to avoid, yes? I personally think writing a function to solely include a file is very counter productive. I thought nowadays everyone used PSR autoloading? Failing that, why can't you just include the file conditionally? Whilst there are better ways, after your script has ran, try using http://php.net/manual/en/function.get-included-files.php - to get a list of included files. E.g. $files = get_included_files(); var_dump( $files ); A bit harsh? lol I am aware of these things, but my answer to that. Is that the project is way too dependent on word-press and so the design was flawed from the first line (since there wasnt much planning), its too late to do anything now, so we are just trying to manage it until we can migrate to OOD.. But the method of separating the legacy coding style in includes files, seems to be working just fine for the project...if anything its been quite efficient and manageable and we are launching tomorrow. I get that "everyone" is doing autoloading, yet thinking outside the box is not always a bad thing.
August 27, 201412 yr Author Well no, autoloading is a much better approach. You don't need to care about anything once you're autoloading, and you're also not loading lots of stuff you don't need either. Also, doing what you've done literally ties your function calls to your file system, which makes your code less portable and even means you'd have to call functions in a certain order in order for the right includes to have been called. You're approaching messy code with a solution that will just produce more mess. The fact that you're not identifying the tight coupling here to me implies that you're probably not writing object oriented code at all. Also, thinking "outside of the box" can be good at times, but sometimes things become conventions for good reasons. Attempting to program your website in assembly would also be "thinking outside of the box", but that doesn't make it a good idea. I not using classes, i told you i wasn't and I don't remember saying it wasn't better. This is just a solution until we can redesign the site. But we had to launch, so that's, that. The solution that we are using, seems to working just fine for now. But please remember I was asking a question that was relating to the server workings, not design conventions...or your assumptions if i am or am not using OOP
Create an account or sign in to comment