HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpModerate

Open source PHP framework

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
sourcephpopenframework

Problem

So I have started a PHP framework called ExCx and I haven't really had much experience in the professional development business.

I was just wondering if my structure/layout/methods are up to scratch?

EDIT: Forget the URL, added that.
Normally I remember to omit the closing php tag...

In tandem with this I am building a PHP Blocks type thing, It's still early days for both projects.

```
0)
{
array_shift($backtrace);
$remove_lines--;
}

$backtrace = array_reverse($backtrace);

$bt_string = '';
$i = 0;
foreach ($backtrace as $call)
{
if ($i)
{
$bt_string .= "\n";
}
if (isset($call['file']))
{
$bt_string .= str_replace($doc_root, '{doc_root}' . DIRECTORY_SEPARATOR, $call['file']) . '(' . $call['line'] . '): ';
} else
{
$bt_string .= '[internal function]: ';
}
if (isset($call['class']))
{
$bt_string .= $call['class'] . $call['type'];
}
if (isset($call['class']) || isset($call['function']))
{
$bt_string .= $call['function'] . '(';
$j = 0;
if (!isset($call['args']))
{
$call['args'] = array();
}
foreach ($call['args'] as $arg)
{
if ($j)
{
$bt_string .= ', ';
}
if (is_bool($arg))
{
$bt_string .= ($arg) ? 'true' : 'false';
} elseif (is_null($arg))
{
$bt_string .= 'NULL';
} elseif (is_array($arg))
{
$bt_string .= 'Array';
} elseif (is_object($arg))
{
$bt_string .= 'Object(' . get_class($arg) . ')';
} elseif (is_string($arg))
{
// Shorten the UTF-8 string if it is too long
if (strlen(utf8_decode($arg)) > 18)

Solution

I haven't read the source code entirely, but here a few things that came to mind immediately:

  • Use PHP Docblocks, so my IDE can support me when using your code



  • Please break down backtrace() into smaller functions which are understandable in an instant or insert some inline comments above those crazy if/else/string operations in this function.



  • Omit the closing ?> when you have a PHP only file, because it might give you alot of headaches (weird spaces popping up in your HTML output which you won't find easily)



  • Make __construct and __clone (even if they don't contain any code) private if you have a static class. This way somebody who uses your class and doesn't bother to look into the source or docs will realize how to use your class faster.



  • Don't use String concatenation (.=) in a loop. Build some kind of data structure like an array within this loop and implode() afterwards. Much easier to understand and faster since concatenating strings is very expensive.



  • If you want other people to use and maintain your code, please provide at least better description what this code does, some sample usage and output.

Context

StackExchange Code Review Q#2986, answer score: 12

Revisions (0)

No revisions yet.