It's good that it's working for you. But I don't recommend you to use eval as I don't see any need.
I like simple code. You can put all that content of php2 in a function and pass the value when calling it. In that function accept the value in a variable and use that variable where you want to use.