-

2011年8月1日星期一

What does this php line of code do? Running Joomla! on wamp?

-What does this code do in a .php file I'm encountering an error here, but I don't know what the if() function is doing. I'm kind of a newbie.



I'm trying to run my Joomla backup on my wamp server.



file: \libraries\joomla\cache\storage\memcache .php



class JCacheStorageMemcache extends JCacheStorage



function __construct( $options = array() )

{

if (!$this->test()) {

return JError::raiseError(404, "The memcache extension is not available");

}

parent::__construct($options);



$params =& JCacheStorageMemcache::getConfig();

$this->_compress = (isset($params['compression'])) ? $params['compression'] : 0;

$this->_db =& JCacheStorageMemcache::getConnection();



// Get the site hash

$this->_hash = $params['hash'];

}



Any help would be appreciated.The Syntax of if() is this:



if ( boolean_expression ) {

聽聽聽聽action_if_true

}



This means the boolean expression is evaluated, boolean can be true or false, if the expression is true then the action inside the { } is performed.



In your code:



if (!$this->test()) {

聽聽聽聽return JError::raiseError(404, "The memcache extension is not available");

}



$this is the active object. $this->test() is a call to a method contained within the active object called test(). This method will return either true or false. At this point if the test returns true then the code in { } would be executed. the ! is a negation operator, this flips the boolean result, making false become true and true become false.



So your code is actually making whatever test() returns flipped. So the code body only executes if test is false, then flipped to be true. In plain English the code body executes only if the test fails.



if (!$this->test()) {



If the test on $this fails then execute the body. The body is:



return JError::raiseError(404, "The memcache extension is not available");



Return, instructs the code execution to exit the function [we are inside the function __construct]. JError::raiseError() is a method used to send errors, this particular version has two arguments, an index specifying the number and a string specifying the message. In this case 404, "The memcache extension is not available"



If you want to prevent this error, then check the body of the test() method and find out why the test is failing.

没有评论:

发表评论