r/PHPhelp • • Jul 26 '25

Basic php Help, Include Error, Pathing Issue?

Started coding in php , but I can't seem to use "include" or "require_once", really basic level stuff, syntax is correct because if I drop the file directly into the code it runs without issue, but if I try to pull a saved file I run into an error

code to call -

<?php include 'includes/footer1.php';?>

code being called -

<footer> &copy; <?php echo date('y')?></footer>
</body>
</html>

Warning: include(includes/footer1.php): Failed to open stream: No such file or directory in C:\xampp\htdocs\New folder\class_objects.php on line 46

Warning: include(): Failed opening 'includes/footer1.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\New folder\class_objects.php on line 46

both files are saved in my root folder, so what am I doing wrong here.

3 Upvotes

38 comments sorted by

View all comments

Show parent comment

4

u/colshrapnel Jul 26 '25

I find it bad practice

Unfortunately, nobody else agrees with you. I would suggest to freshen your PHP knowledge.

-1

u/[deleted] Jul 26 '25

I find the 'nobody else' to be no one but you. As I haven't seen anyone chime in yet. And there is only 6 people who has looked at this and they seem to not want to nor care to chime in.

6

u/MateusAzevedo Jul 26 '25

You really should get back and relearn the basics. Everything you said in your comments is wrong.

2

u/mtetrode Jul 26 '25

I will chime in

Your advice is wrong, in all paragraphs there is at least one error.

You do not help the OP, only tell him that this is wrong and that is not good.

Why?

OP is someone that is starting to learn to program in PHP. I will not tell him to use Symfony components as Laravel uses too much behind the scenes magic, or that Postgres is purer than MariaDB.

I would - if it wasn't 0:30 in my timezone, write a helpful post with just enough examples to get the OP started

/rant

-2

u/[deleted] Jul 26 '25

I don't use php with crutch programs like larvell or anything.

I don't even use ruby on rails or any of that extra junk.

or even rely on symphony because I don't lean on dependencies.

All of that can be attack vectors.

2

u/equilni Jul 26 '25

I don't lean on dependencies.

All of that can be attack vectors.

Really????? Did you write your own OS and hardware drivers too?

1

u/[deleted] Jul 26 '25

sometimes. Why?

2

u/equilni Jul 26 '25 edited Jul 26 '25

I chimed in, but please post on r/php your best practices so we can review. Perhaps we are all doing it incorrectly.

Please, o please, help us be better developers.

1

u/sneakpeekbot Jul 26 '25

Here's a sneak peek of /r/PHP using the top posts of the year!

#1: Anyone else still rolling this way? | 219 comments
#2: PHP is a hidden gem!
#3: PHP is Still the King!


I'm a bot, beep boop | Downvote to remove | Contact | Info | Opt-out | GitHub

0

u/[deleted] Jul 27 '25

I guess its better than what wordpress came up with: using functions to call header and footer, etc. Because executing functions is really slow compared to include.

Why didn't they just expand append and pre-append node like in php-xml? But with html?

2

u/equilni Jul 27 '25

Because executing functions is really slow compared to include.

I take it classes are even slower?

1

u/[deleted] Jul 27 '25

Hey man, I am not looking to pile on you, but you were in fact wrong in about every statement you made, although I do think you might be having some issues communicating what you meant. With that said, this thread was about the php include function not including a file. This is one of the reasons I use require_once, as a failed include should never be ok.

Colshrapnel, Mateus and others have been working primarily with PHP for a long time, and routinely provide help and advice to others.

At this point, my advice would be to relax and stop taking things personally. Be open to questioning your assumptions. Sometimes you find out something you believe to be true is not.