Jump to content

benanamen

Members
  • Posts

    2,134
  • Joined

  • Last visited

  • Days Won

    42

Posts posted by benanamen

  1. Just making a suggestion as this is what this forum is for. Not looking to get into an argument about it.

     

    Why should there be a forum/a few forums for subjects that nobody (on this site) asks questions about?

     

    Probably because there is no specific forum for it.

     

    We are PHP Freaks. Would you go to RailsForum.com to ask a PHP question if they had a forum for it? 

     

    Now you're getting ridiculous. This site has NUMEROUS SPECIFIC forums that are not php. Javascript Help, Html Help, CSS Help,........... And if I was already at the rails forum I probably would if there were knowledgeable people there.

     

     

    benanamen, on 07 Oct 2016 - 11:29 AM, said:snapback.png

    This site may as well just have a php forum and other forum only then.

    Reductio ad absurdum

     

     

    Whatever your trying to say here, the rails forum you link to is exactly that. Rails and other. This is not a pure php site like the rails site is pure rails.

  2. "Other" is pretty generic and does not group the topic types. This site may as well just have a php forum and other forum only then. It takes a couple seconds for a mod to add a specific forum so what will it hurt to add it, popular or not?

     

    I currently leave this site to other forums for the "other" technology stuff. The first top two priorities for a site owner is to get people to their site and to keep them there. IMO, phpfreaks has the most knowledgeable experts than any other forums I am on.

  3. I would like to propose that new specific forums are added to this site for Ruby/Rails, Python and Java and perhaps others. (Yeah, I know it's "PHP Freaks"). It would be beneficial to this site and its users. It is also common on other coding sites to cover all the various technologies.

  4. Not really. Unfortunately, PHP isn't a great language for learning OOP, because all OOP parts have been added on top of the procedural paradigm at a very late stage. This is why they often seem unnatural and hard to understand. If you're really interested in OOP, you should consider learning it together with a language that has been designed in an object-oriented manner from the ground up. My personal favorite is Ruby (which is a scripting language), and of course there are classical OOP language like Java (which is heavier).

     

    Am I better off heading straight to ruby first? Does ruby knowledge transfer over to Php OOP? Are you on any ruby help forums?

  5. The reason why you should declare attributes (with a line saying public/protected/private $attName) is that you need to know the attributes of an object to write correct code.

     

    That answers an upcoming question I had. With all these classes in an app, how do you know how to use them. 

     

     

    Unfortunately, the example code is a fairly bad example.

     

    That is the problem I am going to run into until I get this down. I wouldnt know bad OOP staring me in the face. Any OOP tutorial recommendations?

     

     

    The var keyword comes from PHP 4 and is long obsolete. If you see it being used in a tutorial, pick a different tutorial.

     

    This is worth it's weight in gold!

     

    When you explain things the way you just did I can get a good grasp of it. All the tutorials I have seen don't really explain in detail. They just say do this, do that.

     

    So, if I understand correctly I don't want to do protected $username =""; right?

  6. So now this tutorial I am studying uses another example and the same type of line previously asked about equals an empty string public $username = "";. I tried it without the empty string like public $username; and it still works. What is there to know about this?

     

    Any recommendations that give detailed explanations of the code?

     

    * Edit, now elsewhere I am also seeing var $some_variable; for the same type of line. So there is Public, Private, Protected and Var?

     

    OOP is making my head hurt.

    <?php
    class Member
        {
        public $username = "";
        }
    $member           = new Member();
    $member->username = "Fred";
    echo $member->username;
    ?>
    
  7. Appreciate the response, but when it comes to OOP I need answers really dumbed down until I get a grasp of this. I want to understand why to do things and not just do it because it works.

     

    PHP can add properties dynamically

     

    How does it do that?

     

    but you should avoid this at any cost

     

    How do you avoid it? By having the line in question? Would that line generally be public or private? Is it just because you won't get documentation or are their more reasons? Is their any special name for a property with no value like the line mentioned?

     

    you won't get code completion, and you cannot easily distinguish between legitimate attributes which just aren't declared and plain programming errors

     

    Lost me here. I looked up code completion and it seems to only apply to IDE's and thus far is the only place I have been aware of it. The rest is russian to me so far.

  8. In the following class, it works with or without line 4 public $num. So why is it there?

    <?php
    class mathematics
        {
        public $num;
    
        public function addTwo()
            {
            return $this->num + 2;
            }
        }
    
    
    $math = new mathematics;
    $math->num = 3;
    
    echo $math->addTwo();
    ?>
    
  9. So now I have some classes that need to be used by the application. From what I can gather, now I need to know several things to "include" them in the app such as Namespaces, spl_autoload_register, and PSR-4.

     

    Could someone please put these things in perspective and when/how to implement. I have read up on each of these items. I am not grasping it as of now.

     

    It also seems to be that their is a particular directory structure for the class files and not just a single directory with all the class files in it.

  10.  

    Oh, I very much get that. As the link you referenced starts "Our client has come up with the requirement that". As I said, this is just for practicing OOP right now and was old procedural code from long, long ago.

     

    The class as you have modified it is very clean now. I will just remove the password storage and it should be good to go.

     

    More importantly, I just picked up a couple more tidbits of OOP knowledge which was the purpose of doing this in OOP. 

     

    Thanks!

  11. Are you storing the plaintext password when the log-in fails?

     

    Currently it does. It should be logging Bad Username/Bad Password and Valid username/Bad password. I know right now it will also do the undesired bad username/good password which is a fail since a good pass is in plain text. This started from an old procedural login code and right now is just for learning OOP. The idea was to see when a login fails, what was entered when it failed.

     

    * Edit: Original code did not log good password in plain text.

     

    I see what you did with the PDO type declaration. I never would have got that from the Manual. Does that fall under the self type on the man page linked to?

     

    Agree with your class name suggestion

     

    • When you have multiple methods doing almost the same thing, create a private or protected method for the common code and call that in the public methods instead of literally duplicating the code.

     

    I could see that it was near duplicate code and figured that was an area that could be improved. With that said I don't understand how to implement what you just said. I do get the gist of it, but implementing in OOP I am lost at the moment.

     

    I still have less than 24 hours into serious OOP study.

  12. I was practicing OOP and made a simple class to log logins. Does anyone see any problems with this or improvements that can be made? Any issue with using NOW() in the query string instead of a placeholder?

     

    In another thread, @Jaques1 said:

    You should also use type declarations in your methods to make sure that the $pdo argument is in fact a PDO instance.

     

    How would I implement that? I rtfm and don't understand it as of yet.

    <?php
    // ----------------------------------------------------------------------------
    // Database Connection
    // ----------------------------------------------------------------------------
    
    $dbhost = 'localhost';
    $dbname = 'test';
    $dbuser = 'root';
    $dbpass = '';
    $charset = 'utf8';
    $dsn = "mysql:host=$dbhost;dbname=$dbname;charset=$charset";
    $opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ];
    $pdo = new PDO($dsn, $dbuser, $dbpass, $opt);
    
    //------------------------------------------------------------------------
    //
    //------------------------------------------------------------------------
    
    $valid_login = new LogLoginStatus($pdo);
    $valid_login->validLogin('goodusername');
    
    $invalid_login = new LogLoginStatus($pdo);
    $invalid_login->invalidLogin('bad_username', 'bad_password');
    
    //------------------------------------------------------------------------
    //
    //------------------------------------------------------------------------
    
    class LogLoginStatus
        {
        /**
         * Log Valid/Invalid logins
         *
         * @param string login_username
         * @param string login_password
         */
    
        public function __construct($pdo)
            {
            $this->pdo = $pdo;
            }
    
        function validLogin($username)
            {
            $sql  = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())";
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute(array(
                1,
                $_SERVER['REMOTE_ADDR'],
                $username,
                '***'
            ));
            }
    
        function invalidLogin($username, $password)
            {
            $sql  = "INSERT INTO user_login (login_status, login_ip, login_username,login_password, login_datetime) values(?, INET_ATON(?), ?, ?, NOW())";
            $stmt = $this->pdo->prepare($sql);
            $stmt->execute(array(
                0,
                $_SERVER['REMOTE_ADDR'],
                $username,
                $password
            ));
            }
        }
    ?>
    
    CREATE TABLE `user_login` (
      `login_id` int(11) NOT NULL AUTO_INCREMENT,
      `login_status` tinyint(1) DEFAULT NULL,
      `login_ip` int(10) unsigned DEFAULT NULL,
      `login_username` varchar(255) DEFAULT NULL,
      `login_password` varchar(255) DEFAULT NULL,
      `login_datetime` datetime DEFAULT NULL,
      PRIMARY KEY (`login_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
  13. When I click the quote icon there is no new line. It is a single line which is how I would expect for it to remain when I click post, but it adds in a line after clicking post.

     

    While we are at it. There is another longstanding problem I have had. There is no way for me to add attachments. I can click my media and select something that I somehow was able to attach at one point in time. I can't add anything new.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.