Quick question. Is it okay to save a PHP class file as myClass.class and include it in other “regular” .php files?
It works just fine in PHP 5.3, but I’m wondering if it is bad practice.
tl;dr:
useObjects.php
<? include('myClass.class');
$my_object_1 = new myClass();
?>
myClass.class
<?
//constructors and functions
?>
Thank you!
EDIT: This is just for my own organization.
The only technical reason not to do this is if the web server is not configured to parse
.classfiles as PHP scripts, and if a file is beneath the document root and accessed via the browser, it will display PHP source code to the end user exposing source code or sensitive data like database connection details.Beyond that, it’s a matter of convention. And while PHP doesn’t have too many conventions to speak of,
.classis a pretty unusual one.*.class.phpis fairly common, however.