Jump to content

justsomeguy

Moderator
  • Content Count

    31,046
  • Joined

  • Last visited

  • Days Won

    41

justsomeguy last won the day on November 21

justsomeguy had the most liked content!

Community Reputation

1,087 Excellent

About justsomeguy

  • Rank
    More Human Than Human
  • Birthday 06/03/1979

Contact Methods

  • Website URL
    http://
  • ICQ
    0

Profile Information

  • Location
    Phoenix

Previous Fields

  • Languages
    Focusing on PHP and JavaScript

Recent Profile Visitors

289,309 profile views
  1. justsomeguy

    Problem with array

    What questions do you have? You can use Array.push to add a value to the end of an array, and Array.indexOf to check if a value already exists. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
  2. justsomeguy

    Issue extending class

    If your design goal is to minimize the lines of code in the child class, you're going to end up with a bloated parent class. Maybe you're thinking of some version of a factory pattern where you have a factory class that creates other classes based on what you pass to it. Look into that and see if it applies, but I would recommend not doing anything for any child class inside a parent class. Your goal should be to keep the parent class (and all classes) clean and easy to understand. If you tie things up in a way where you're calling methods from child classes inside parent classes then you're going to make debugging more difficult and you're starting to introduce requirements in your classes which will degrade the reusability and flexibility goals of OOP. Or, at a minimum, move that code which calls some initialization function to the child's constructor instead of the parent's constructor, so that each child class can do whatever it needs to be done.
  3. justsomeguy

    Issue extending class

    And why are you doing that from the superclass and not the child class? I still have no idea why you would instantiate a child class inside a superclass. I don't know what the purpose is. I have never heard of anyone doing that, I haven't even heard of a use case for it. If you think about classes extending other classes, there are multiple analogies. Maybe you have a "food" class. Then you extend the food class to make a "fruit" class. Then you extend the fruit class to make an "apple" class. You're talking about creating an instance of apple from inside the general food class and that makes no sense at all to me why you would want to do that. Why is everything of type "food" required to do something with an apple? If I'm creating an object for rice, or for eggs, why are they messing with apples? It doesn't make sense, the way that's organized does not make sense. Object-oriented programming should be extensible, reusable, and flexible, and when you're creating an instance of a child class inside a superclass you're violating one or more of those goals. The major reason why it doesn't make sense is because the child class presumably implements a set of methods or properties that the superclass does not. That's the point of extensibility. The superclass doesn't know anything about those additional methods or properties. So why does it make sense for the superclass to create an instance of that object and then try to use methods or properties that were not defined in the superclass? Why am I creating an instance of a Food object which immediately tries to remove seeds that might not even be there?
  4. justsomeguy

    Specific permissions to access files

    That doesn't sound like a workable solution.
  5. justsomeguy

    Issue extending class

    Right, it makes sense to have a superclass for this, what I don't understand is why you would instantiate a child class inside the superclass.
  6. justsomeguy

    Issue extending class

    I'm a little confused why you're doing it that way. If the only thing the constructor does is call a single method, why isn't that method the constructor? And there's no reason to set and then immediately get the value again. Also, if those are parameters it seems like it would be a little more flexible. class Module { public $name; public function __construct($module, $method) { $this->setName($module); $this->setMethod($method); $moduleInstance = new $module(); $moduleInstance->$method; } public function getName() { return $this->name; } public function setName($name) { $this->name = $name; } public function getMethod() { return $this->method; } public function setMethod($method) { $this->method = $method; } } class Site extends Module { public function __construct() { parent::__construct('Site', 'indexAction'); } } $site = new Site(); Now, what's the issue you were trying to describe before? Are you saying you want multiple module instances but for some reason you only want one of them to instantiate a site instance? This seems a little backwards also. Class A extends class B, but you create an instance of class A inside class B. You're creating an instance of an extended class inside the class that gets extended. What's the point of that? I don't see a reason to do that, why not just instantiate a single instance of site? Why are you explicitly instantiating module at all if you've extended it?
  7. justsomeguy

    Specific permissions to access files

    Apache, for example, has modules that change its behavior. Some well-known ones are things like mod_rewrite or mod_expires. One option would be a custom module like that which would handle the authentication and authorization so that the web server could still do its job serving the actual files.
  8. justsomeguy

    Specific permissions to access files

    One option is to route all requests for those files to a PHP script that authorizes people before sending the file content, and having the actual files stored outside of the web server root. You could also use a custom web server module to do authorization.
  9. justsomeguy

    Issue extending class

    If you don't want to run a function when you call the constructor, then you can't run that function when you call the constructor. This code is a little too abstract to say why you wouldn't want to call the function more than once, but maybe just call it explicitly instead of in the constructor. Maybe use a static property to tell whether or not it's already been called. Maybe use a parameter that determines whether it should be called.
  10. justsomeguy

    Force data into unique row format

    You'll need to get the list of IDs and names and figure out which one to use, and just insert that data into the new table.
  11. justsomeguy

    Grid Layout: place-self

    https://developer.mozilla.org/en-US/docs/Web/CSS/place-self
  12. justsomeguy

    Issue extending class

    Put a constructor in ThirdClass.
  13. justsomeguy

    Issue extending class

    The constructor is only inherited if you don't define one, so the solution is to define a constructor. If you have a constructor and want to call the parent constructor explicitly you can use parent:: for that. That is often the case, but the parent constructor is not called automatically because sometimes you want to parent constructor to run either before or after the child constructor, so that behavior is left up to the programmer to do explicitly. So the behavior you are expecting is the default behavior when you have a constructor. Therefore, it sounds like the solution is to make a constructor.
  14. justsomeguy

    Issue extending class

    That's all of your code? What error message do you get?
  15. The old mysql extension was removed from PHP 7. The best replacement is to use PDO with the appropriate driver. You can also use mysqli, but most programmers prefer PDO. You're also using 2 underscores instead of 1, but if you fixed that you would get the same error message because the mysql extension has been deprecated since 2004. They finally removed it in PHP 7.
×