Skip to Content
PHP, MySQL, JavaScript & HTML5 All-in-One For Dummies
book

PHP, MySQL, JavaScript & HTML5 All-in-One For Dummies

by Steve Suehring, Janet Valade
April 2013
Beginner to intermediate
720 pages
15h 43m
English
For Dummies
Content preview from PHP, MySQL, JavaScript & HTML5 All-in-One For Dummies

Chapter 1: Improving Your PHP Programs

In This Chapter

arrow.png Including helpers automatically

arrow.png Reusing code

In earlier chapters, you’ve seen how to program in PHP. You’ve seen how to create a program, how to loop, set up conditionals, and more. All of that knowledge has enabled you to create PHP programs that work well on the web. But you can make them even better, even easier to use, and that’s what this chapter is all about.

In this chapter you’ll see how to improve and extend your PHP programs and how to create and use helper functions automatically. You’ll also see ways to reuse code rather than reinventing it every time you need it.

Automatically Including Helper Functions

Once your programs reach a certain length and complexity, you find that there are a lot of includes and require_once() functions. Each time you make a new file or try to make something into a common function, you also need to go back through all the programs and add a new require_once. That can quickly become monotonous. Luckily, there's a way around it.

Using auto_prepend_file

You can automatically prepend a PHP file so that its code is executed before the actual file being requested. In other words, if you send a visitor to a URL similar to http://www. example.com/login.php, you can use auto_prepend_file to always ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PHP and MySQL Web Development: A Beginner’s Guide

PHP and MySQL Web Development: A Beginner’s Guide

Marty Matthews

Publisher Resources

ISBN: 9781118231340Purchase book