How to fix PhpStorm errors on HTML code?
Hello:
I'm new to PhpStorm (and PHP) overall. I have PHP 7.1 and Apache 2.4.28 installed. I did NOT use an AMP bundle. In the Jetbrains tutorial, I also did NOT install vagrant or a VM, since I'm new, I'm trying to start without using too many tools so I can get an understanding of how PHP works.
The Apache install is working and I can test both that and PHP by putting:
<?php
phpinfo();
?>
in a webpage and viewing it from a browser.
In PhpStorm, in Settings -> Languages & Frameworks, I have PHP Language level set to my install, 7.1, and the CLI interpreter also set to 7.1. In Run -> Edit Configurations -> Built-in Web Server, I added an entry for "MyApache", the host is localhost, port is 8080, and the Document root is c:\apache\latest\www.
When I create a new project, and go to File -> PHP file, I put in this in the file:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
It errors on every markup tag with:
Declaration of referenced constant is not found in built-in library and project files.
Expression is calculated but the calculation result is not used anywhere. This may be caused by a misspelling when the '=' operator is replaced with '==' by mistake.
I'm really confused. Those errors, especially the second one, have nothing to do with my code. I'm just trying to see how PhpStorm and PHP work by generating a hello world webpage.
Where am I going wrong here? Any suggestions on how to proceed are greatly appreciated.
Thanks!
Please sign in to leave a comment.
Hi there,
Please post a screenshot of the whole IDE window with error visible.
@Andriy... Thanks for the reply! I'll put two screen shots in here... the first one shows the entire code. The second one has the code obscured by the complete error being visible. Thanks again.
Well.. IDE is absolutely correct here; it's your "new to PHP" thing.
You have put HTML code inside (after) <?php opening tag (see first lane in your file) .. which is opening tag for PHP code...
If you need the top comment section -- just close PHP code block with ?> after the comments / before your HTML code. if you do not need comments block -- just delete everything before the HTML code.
Yeah ... you basically did nothing.
Once again -- you did put HTML tags inside PHP block (between <?php ... ?>). That's wrong .. because now IDE (and PHP) treats <html> as PHP instruction .. which is obviously wrong.
Use your initial code sample as whole file content -- that's all you need.