PHP File inclusion Issue

Live Link

Why it is unable to include the file. i am learning from a Lynda Video, and I have used an online database on hostgator.

Because you are calling the filename wrong. You named it with all lower case, but you are including it as ParseCV. You should also try to restrict who sees what on your site. I can see all of your projects which I should add, has tons of incorrect syntax. It’s also the reason why I was able to figure out that you named it with lower case, but calling the file with capitalizations. PHP is case sensitive when it comes to including a file. It has to be exact or you’ll get an error. Also, start using require or require_once instead of using include. If you keep using include and you get more errors that has nothing to do with the current file, you’re going to be spending a hafty amount of time debugging where the problem starts.

2 Likes

I sill could not figure out where exactly the alphabetical cases are playing the issue because I believe the inclusion is generated somehow dynamically:

  function my_autoload($class) {
    if(preg_match('/\A\w+\Z/', $class)) {
      include('classes/' . $class . '.class.php');
    }
  }

I have not written this code. I am just trying to grasp and learn as much as I can from the code written buy Lynda authors.

<off topic>

I am unable to grasp the basics of OOP’s. Do you have any recommendation from where I can successfully incorporate the programming in my soul?

</off topic>

If the class filenames are all lowercase, use strtolower($class) in your require_once

2 Likes

I don’t usually mess around with regex and maybe someone more familiar with it can help you. I am pretty sure it’s because your regex is requiring the first letter of the file to be a capitalized letter and some where in there, requiring part of the filename to be capitalized as well. I maybe wrong.

As for OOP, I personally don’t recommend it if you don’t understand basic PHP. It’s more complex for someone who doesn’t understand how logic may be applied. There are many techniques and many ways to implement OOP. You have to understand how each piece relates to one another.

1 Like

Thanks. I have made it like this →

seems most of the errors are gone.

Ca you suggest any learning path to follow. Like read such and such book etc for next few weeks so that i can become comfortable. Please advise in any manner you can help me to further my learning trajectory.

  1. db_connect is a function, not a class. You can only autload classes, and not functions.

  2. You should not mess around with autoloading yourself, you should use PSR-0 or PSR-4 instead, or use composer to manage it for you.

4 Likes

Thanks this is not my code sir, but Lynda.com’s author. i am trying to copy paste and take away as much as I can.

I haven’t read it myself, but I’ve heard good things about https://www.sitepoint.com/premium/books/php-mysql-novice-to-ninja-6th-edition

2 Likes

Nobody ever learned anything from copy paste.

2 Likes

copy paste was actually a negative word. what I wanted to say was just trying to reproduce.

Totally agree with @rpkamp. If you really want to learn OOP, then the link rpkamp gave you is pretty good. I know I don’t speak for most people, but when I first tried to learn OOP, it was actually difficult for me. Since I was learning it by myself and I had really no help, it was pretty hard for me to grasp the concept of it. I remember asking a few members on here once for links to help me, but it still didn’t help much.


Basically, I had to change the way I was thinking in order to understand the concept of OOP. As far as I understand it, you split the task and divide it into pieces. After that, you combine it all at the end. So for instance, if you have a huge code base and each piece of the code can actually do different tasks, it doesn’t make sense to mush it up into 1 function. Say a piece of the code is for updating something and another piece of the code is for checking for version numbers. The concept of OOP is to make those tasks into 2 separate functions and then combine the result at the end. That’s how I normally see it. Some may see it differently.

1 Like

This talk is also awesome to get a sense of what you can do with OOP: https://matthiasnoback.nl/talk/beyond-design-patterns-and-principles-writing-good-oo-code/

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.