I have a site architechure where I assign content to variables and then print them in a master page. My problem is that php code in the sub pages is imported into the variab
Using file_get_contentsDocs will return the actual file's content. But you're looking to execute the file instead. You can use includeDocs to execute a php file, however most often that file will create output itself already. This is probably not what you want.
Instead, you can still use include but catch the output into a buffer. This is called output-buffering Docs.
To make this more accessible for your program, you can create a small helper function that deals with the details. You can then just call that function that will include the file in question and return the actual output. You can then assign the return value to your variables.
Example:
Related: Answer to Modify an Existing PHP Function to Return a String