Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need some help with an error I have not encountered before and can't seem to find anywhere.

In a PHP mvc framework (just from a tutorial) I have the following:

// Initiate the class
$className = 'Controller_' . ucfirst($controller);
if (class_exists($className)) {
 $controller = new $className($this->registry);
}

$className is showing the correct class name (case is also correct). But when I run it I get this in the apache error log (no php error)

[Wed Mar 31 10:34:12 2010] [notice] child pid 987 exit signal Segmentation fault (11)

Process id is different on every call. I am running PHP 5.3.0 on os x 10.6. This site seems to work on 5.2.11 on another Mac. Not really sure where to go next to debug it. I guess it could be an apache setting as much as a php bug or a problem with the code... any suggestions on where to look next?

The error does not appear on commenting out that code. I also have about 15 other php sites running with no problems. Including others using the same base mvc framework

share|improve this question
6  
Since it's a segfault there doesn't have to be something wrong with the script but definitely with the php build. A script should never be able to crahs the php instance (so hard that the os has to terminate the process). –  VolkerK Mar 31 '10 at 10:52
    
Do you get the segfault if you comment out that line of code? (i.e. is it definitely these 4 lines of code causing the problem?) –  Andy Shellam Mar 31 '10 at 10:52
    
I'd assume this to be caused either by faulty hardware or by any of the modules loaded in Apache. Voting to move to serverfault. –  Gordon Mar 31 '10 at 10:54
    
Why has a programming question been migrated away from SO? –  John Gardeniers Sep 24 '10 at 9:32
    
Because the error is not from the code, but from the php built. –  Anarko_Bizounours Jun 21 '11 at 15:09
add comment

migrated from stackoverflow.com Mar 31 '10 at 11:23

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 1 down vote accepted

I remember having the exact same issue. If I remember correctly the problem was recursive instantiation, i.e. PHP ran out of memory, which caused the segmentation fault. Check that the instantiation of $className does not go around in circles.

share|improve this answer
add comment

Try this:

// Initiate the class
$className = 'Controller_' . ucfirst($controller);
if (class_exists($className)) {
     // construct the code string and evaluate it.
     $code='$controller = new ' . $className . '($this->registry);';
     eval($code);
}
share|improve this answer
add comment

I think you problem is from your own mac. If you did try the website from another computer and did not get the error, then that mean you'll need to reinstall you php package. Something went wrong at some time with your php built (maybe an update, or an link destroyed because of new installation...)

Hope this will help you.

share|improve this answer
add comment

Try using curly braces around your class name variable. See below in the $controller assignment line.

$className = 'Controller_' . ucfirst($controller);
if (class_exists($className)) {
 $controller = new ${$className}($this->registry);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.