help me understand line of code

Status
Not open for further replies.

Mutikasa

Active Member
314
2011
36
0
What does this code do?
Code:
$changedDir='';
if (!$changedDir)$changedDir = preg_replace('|wp-content.*$|','',__FILE__);

why if (!$ChangedDir)$changedDir? what kind a expression is that?
 
4 comments
The first line and the if statement is useless there. $changedDir is empty and if statement would always turn to true since $changedDir is empty.
PHP:
$changedDir = preg_replace('|wp-content.*$|','',__FILE__);
The above statement seems like its trying to get the root path / Wordpress directory where wp-contents folder is located (incase this is stored in a theme file or plugin). Its removing everything after and including wp-content in __FILE__ (which gives the current file path)
 
The first line and the if statement is useless there. $changedDir is empty and if statement would always turn to true since $changedDir is empty.
Is it same as
Code:
$changedDir=''; 
if (!$changedDir)
{
$changedDir = preg_replace('|wp-content.*$|','',__FILE__);
}
I'm confused why there isn't empty space between if (!$ChangedDir)$changedDir?
It doesn't have to be?

I thought it was some kind of casting like in c#
 
Is it same as
Code:
$changedDir=''; 
if (!$changedDir)
{
$changedDir = preg_replace('|wp-content.*$|','',__FILE__);
}
I'm confused why there isn't empty space between if (!$ChangedDir)$changedDir?
It doesn't have to be?

I thought it was some kind of casting like in c#
PHP is whitespace insensitive, so there could be space or not even. Even in C#, that kind of statement would compile fine. Casting couldn't be done to variable names, you need to specify the type to cast to in that case
 
Status
Not open for further replies.
Back
Top