# Looking for an explanation

- Thread: https://externals.io/message/24165
- Original archive: https://news-web.php.net/php.internals/24165
- Started by Oliver Block on 2006-06-20T23:11:11+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #24165 — Oliver Block — 2006-06-20T23:11:11+00:00

URL: https://externals.io/message/24165#24165

Hello list,

as you are familiar with the source code of php it might be easy to explain 
how the brain of php interprets the following code:

print ($life = "hard") -1;
print "\nlife: {$life}\n";

Best regards,

Oliver

P.S. Actually, the origin of that code was the output of a string literal 
concatenated with count($array) -1

---

## #24166 — Sara Golemon — 2006-06-20T23:21:54+00:00

URL: https://externals.io/message/24165#24166 · In reply to: #24165

> print ($life = "hard") -1;
>
Store "hard" in $life,
Substract 1 from the result of that assignment ("hard")
"hard", when used in a string context is casted to int (0)
0 - 1 == -1
Output result of subtraction (casted to string): "-1"
> print "\nlife: {$life}\n";
>
Concatenate "\nlife: " with contents of $life ("hard") and concatenate that 
with "\n"
Output the result of concatenation

-Sara

---

## #24167 — David Tulloh — 2006-06-20T23:45:06+00:00

URL: https://externals.io/message/24165#24167 · In reply to: #24165

Oliver Block wrote:
> Hello list,
> 
> as you are familiar with the source code of php it might be easy to explain 
> how the brain of php interprets the following code:

I think that this would be better suited to the startard PHP list.  I
would suggest posting any further followups there.

> 
> print ($life = "hard") -1;

($life="hard") assigns "hard" to $life and returns "hard"
"hard" -1 casts "hard" to an integer to do a math operation, "hard"
casts to 0
0 -1 is -1, so -1 is printed

> print "\nlife: {$life}\n";
Now you simply print the value of $life, "hard"


David
