[PHP] Message Class

Results 1 to 12 of 12
  1. #1
    Die() Secured is offline
    MemberRank
    Sep 2011 Join Date
    /home/SDev/Location
    555Posts

    [PHP] Message Class

    I still consider my self noob so, any input on how I can better myself is greatly appreciated! ;)

    mysql.class.php
    PHP Code:
    <?php
        
    ///////////////////////////////////////////////////////Message Class (PHP) ////\\
        //
        //Copyright (C) 2012  Secured of RaGEZONE
        //
        /////////////////////////////////////////////////////////////////////////////////
        
        /////////////////////////////////////////////////////////////Documentation ////\\
        //7 Different Types of functions
        //Usage: $doMesage->(*Type*, *Message*, *var1*, *var2, ect....);
        //Types: 1:print, 2:printf, 3:vprintf, 4:sprintf, 5:print_r, 6:echo, 7:return
        //Ex Code: $doMsg->("5", "Random Echo Message");
        //Outcome: Random Echo Message
        //Echos a Message and Returns the Added Message can be used with
        //$var = "foo";
        //$doMsg->("5", $var");
        //Outcome: Foo
        //////////////////////////////////////////////////////////////////////////////////
        
        
        
    class Msg {
            private 
    $type;
            private 
    $msg;
            private 
    $status;
            private 
    $earlyF;

            public function 
    checkInvalidFormat($input
            {
                
    //Some Errors
                
    if($input <= 0)
                {
                    
    $this->status=NULL;
                } else {
                
                    
    $this->status=1;
                }
            }
            
            public function 
    checkStatus($Var
            {
                if(
    $Var==NULL)
                {
                    
    $ei debug_backtrace();
                    
    $this->earlyF "Msg Class:: Incorrect Format. Using function " $ei[0]['function'] . " on line " $ei[0]['line'] . " in file " $ei[0]['file'] . ".";
                    return 
    false;
                    
                } else if (
    $Var==1) {
                
                    return 
    true;
                    
                }   else {
                    
    $ei debug_backtrace();
                    
    $this->earlyF =  "Msg Class:: Status Error. Using function " $ei[0]['function'] . " on line " $ei[0]['line'] . " in file " $ei[0]['file'] . ".";
                    return 
    false;
                }
            }
            
            public function 
    buildMsg($type$message) {
                if(
    $type == "1")
                {
                    print 
    $message;
                    
                } else if(
    $type == "2") {
                    
                    
    printf($message);
                    
                } else if(
    $type == "3") {
                
                    
    vprintf($message);      
                    
                } else if(
    $type == "4") {
                
                    
    printf($message);        
                    
                } else if(
    $type == "5") {
                
                    
    print_r($message);    
            
                } else if(
    $type == "6") {
                
                    echo 
    $message;
                
                } else if(
    $type == "7") {
                
                    return(
    $message);
                }
                
            }
            
            public function 
    sMsg()
            {    
                
    //Grab all arguments slice first argument into two for type and msg and convert to string
                
    $arg  func_get_args();
                
    $this->type implode(array_slice($arg01));
                
    $this->msg  implode(array_slice($arg1)); 

                
    //check format
                
    $this->checkInvalidFormat($this->type);
                
                
    //check status
                
    if(!$this->checkStatus($this->status) == true)
                {
                    
    $final=2;
                    
                } else {
                    
                    
    $final=1;
                }
                if(
    $final !=1) {
                    
                   
    $this->buildMsg("5"$this->earlyF); 
                
                } else {
                
                   
    $this->buildMsg($this->type$this->msg);
                }

            }
        }
    ?>
    Example of how it can be ran.
    PHP Code:
    <?php
    //include
    include_once "inc/class/msg.class.php";

    //test vars
    $var1 "1";
    $var2 "2";
    $var3 "3";
    $var4 "4";
    $var5 "5";

    //test functions
    function dostuff()
    {
        
    $var6 "stuff done!";
        return 
    $var6;
    }

    function 
    dostuff2()
    {
        
    $var6 "stuff done again!!";
        return 
    $var6;
    }

    $msg = New Msg;
    $msg->sMsg("6"$var1$var2$var3$var4$var5dostuff(), dostuff2());

    ?>
    Outcome:
    Code:
    12345stuff done!stuff done again!!


  2. #2
    Account Upgraded | Title Enabled! JaydenC is offline
    MemberRank
    Feb 2012 Join Date
    993Posts

    Re: [PHP] Message Class

    The way you did it is strange..
    If your going to use oop - use it properly.
    Return true / false, etc.
    Nice work, but not proper.

  3. #3
    C:\ WizCoder is offline
    MemberRank
    Aug 2010 Join Date
    JapanLocation
    703Posts

    Re: [PHP] Message Class

    Very .. very .. very strange use of OOP . I still like it though :o

  4. #4
    Not working on UnitedFlyf Mootie is offline
    MemberRank
    Apr 2009 Join Date
    1,589Posts

    Re: [PHP] Message Class

    You should standardize your code formatting more, other than that it looks fine for the most part. However, why not just use the standard printf? I don't see much use for this class as the following would produce the same output.

    PHP Code:
    <?php
    function test1()
    {
        return 
    "stuff done!";
    }

    function 
    test2()
    {
        return 
    "stuff done again!!";
    }

    printf("%d%d%d%d%d%s%s"12345dostuff(), dostuff2());
    ?>
    Here's some useful documentation if you want to use the standard of php code formating.
    Zend Framework: Documentation: PHP File Formatting - Zend Framework Manual

    Also, @Jayden, PHP's support for object oriented coding isn't even complete as far as I know. The standard of object oriented programing itself isn't even definite, why do you say this is using OOPHP improperly? It may be a bit scattered and unnecessary, but that does not make it incorrect usage of OOP.

  5. #5
    Software Person TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,252Posts

    Re: [PHP] Message Class

    I'm sorry, but I don't like it.
    The ugly structure put aside, this class is completely and absolutely unnecessary.

    Don't over-complicate. Wrapping PHP's print-esque functions in a class is a blatant example of over-complicating code, which a lot of novice programmers fall victim to.

    Doing something cool < Doing something simply.

    I'm not sure if I've told this story on RZ yet, but, early in Apple's lifetime, they had their programmers log how many lines of code they wrote for the day.
    One of their programmers logged negative numbers on a pretty consistent basis.
    Can you figure out why? Tip: It's not a bad thing.

  6. #6
    Account Upgraded | Title Enabled! JaydenC is offline
    MemberRank
    Feb 2012 Join Date
    993Posts

    Re: [PHP] Message Class

    Quote Originally Posted by xLethal View Post
    You should standardize your code formatting more, other than that it looks fine for the most part. However, why not just use the standard printf? I don't see much use for this class as the following would produce the same output.

    PHP Code:
    <?php
    function test1()
    {
        return 
    "stuff done!";
    }

    function 
    test2()
    {
        return 
    "stuff done again!!";
    }

    printf("%d%d%d%d%d%s%s"12345dostuff(), dostuff2());
    ?>
    Here's some useful documentation if you want to use the standard of php code formating.
    Zend Framework: Documentation: PHP File Formatting - Zend Framework Manual

    Also, @Jayden, PHP's support for object oriented coding isn't even complete as far as I know. The standard of object oriented programing itself isn't even definite, why do you say this is using OOPHP improperly? It may be a bit scattered and unnecessary, but that does not make it incorrect usage of OOP.
    Well, we all have our habbits. I just wouldn't do it like so, as for you saying that OOP (isnt finished)? You're not entirley wrong but I wasn't talking about oop in general I was talking about his "Habbits".

  7. #7
    Die() Secured is offline
    MemberRank
    Sep 2011 Join Date
    /home/SDev/Location
    555Posts

    Re: [PHP] Message Class

    Quote Originally Posted by timebomb View Post
    I'm sorry, but I don't like it.
    The ugly structure put aside, this class is completely and absolutely unnecessary.

    Don't over-complicate. Wrapping PHP's print-esque functions in a class is a blatant example of over-complicating code, which a lot of novice programmers fall victim to.

    Doing something cool < Doing something simply.

    I'm not sure if I've told this story on RZ yet, but, early in Apple's lifetime, they had their programmers log how many lines of code they wrote for the day.
    One of their programmers logged negative numbers on a pretty consistent basis.
    Can you figure out why? Tip: It's not a bad thing.
    Made for learning not for actual use tho its use able for people who integrate template systems into there websites

  8. #8
    Not working on UnitedFlyf Mootie is offline
    MemberRank
    Apr 2009 Join Date
    1,589Posts

    Re: [PHP] Message Class

    Quote Originally Posted by </Jayden> View Post
    Well, we all have our habbits. I just wouldn't do it like so, as for you saying that OOP (isnt finished)? You're not entirley wrong but I wasn't talking about oop in general I was talking about his "Habbits".
    OOP is generally recognized as object oriented programming. PHP is still is lacking quite a bit of standard object oriented programming features. PHP does not support virtual functions yet, which is a major portion of polymorphism.

    Also, you said:
    If your going to use oop - use it properly.
    I don't see how that can be referring to habbits. Perhaps I should be a bit more clear. Let me ask you, what is proper OOP code if this is improper?

  9. #9
    Account Upgraded | Title Enabled! JaydenC is offline
    MemberRank
    Feb 2012 Join Date
    993Posts

    Re: [PHP] Message Class

    Quote Originally Posted by xLethal View Post
    OOP is generally recognized as object oriented programming. PHP is still is lacking quite a bit of standard object oriented programming features. PHP does not support virtual functions yet, which is a major portion of polymorphism.

    Also, you said:


    I don't see how that can be referring to habbits. Perhaps I should be a bit more clear. Let me ask you, what is proper OOP code if this is improper?
    Eh, TBH There is no "proper" way - Just like if you make an HTML template out of pure html no css and it is compatible with all browsers but it isnt proper. Do you understand now?

  10. #10
    Software Person TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,252Posts

    Re: [PHP] Message Class

    Quote Originally Posted by xLethal View Post
    OOP is generally recognized as object oriented programming. PHP is still is lacking quite a bit of standard object oriented programming features. PHP does not support virtual functions yet, which is a major portion of polymorphism.

    Also, you said:


    I don't see how that can be referring to habbits. Perhaps I should be a bit more clear. Let me ask you, what is proper OOP code if this is improper?
    There are good and bad practices, albeit they are still subject to bias.

  11. #11
    Not working on UnitedFlyf Mootie is offline
    MemberRank
    Apr 2009 Join Date
    1,589Posts

    Re: [PHP] Message Class

    Quote Originally Posted by timebomb View Post
    There are good and bad practices, albeit they are still subject to bias.
    Anything that compiles and runs is "proper" code in my book. It might not be the most organized or efficient way, but it's still proper. There are good and bad practices, yes, but that's based on opinion(even if said opinion is logical). I just think "proper" is a bad word choice as it's pretty unclear especially when saying that they're using something non-definite like OOP improperly. The coding practices may be bad use of OOP in terms of organization and performance, but explain why rather than acting as though there is a set-in-stone correct method to using OOP efficiently.

  12. #12
    Software Person TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,252Posts

    Re: [PHP] Message Class

    Quote Originally Posted by xLethal View Post
    Anything that compiles and runs is "proper" code in my book. It might not be the most organized or efficient way, but it's still proper. There are good and bad practices, yes, but that's based on opinion(even if said opinion is logical). I just think "proper" is a bad word choice as it's pretty unclear especially when saying that they're using something non-definite like OOP improperly. The coding practices may be bad use of OOP in terms of organization and performance, but explain why rather than acting as though there is a set-in-stone correct method to using OOP efficiently.
    I will very much so agree that "proper" is a poor choice of words.

    I think the most important thing to always keep in mind the premise - the goal or advantage, if you will - of the OOP paradigm.
    That, although arguably a bias, would be maintainability.
    The level of maintainability of an OOP application can be linked to numerous things, including how well your code is organized and structured, as well as using good practices and not bad, and so-on.



Advertisement