Activity Stream
48,167 MEMBERS
6782 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 9 of 9
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default How to streamline objects in PHP!

    heya guys, Thought i would just do a quick tutorial on how to streamline objects in PHP!

    Streamlining objects creates a more organized code structure! For example

    PHP Code: 
    $id $root->input->validate->post->id('int'
    Now what this is doing is asking the $root object for the input object, and then we ask the input to give us the validate object, etc etc!

    So how you do this ?

    You use what we call the Magic Methods in PHP Objects

    The magic methods are reserved functions in php, The functions are described below!

    __get
    This allows you to the main streamlining: Example.
    PHP Code: 
    class Test
    {
        function 
    __get($item)
        {
            echo 
    $item;
        }
    }
    $test = new Test();

    $test->LiteWarezIsTheBestXD//This will print out "LiteWarezIsTheBestXD" 
    __set
    This allows you to set variables in the same manner above: Example:
    PHP Code: 
    class Test
    {
        
    $items = array();
        function 
    __set($key,$value)
        {
             echo 
    'adding ' $key ' to $items with the value of ' $value
             
    $this->items[$key] = $value;
        }
    }
    $test = new Test();

    $test->SomeKey 'Some Value'//This will print out "adding SomeKey to $items with the value of Some Value" 
    Ok so combining these to items will allow us to do some pretty sweet things like so!

    PHP Code: 
    class Root
    {
       var 
    $objects = array(); //Where we store other objects

       
    function __set($objectname,$object)
       {
            
    $this->objects[$objectname] = $object;
        }

       function 
    __get($objectname)
       {
          return 
    $this->objects[$objectname];
       }
    }

    //Another Class
    class Input
    {
        var 
    $validator;

        function 
    __construct()
        {
             
    $this->validator = new Validator();//This is a class that valdiates input
        
    }

        function 
    __get($objectname)
        {
            switch(
    $objectname)
            {
                case 
    'validator': return $this->validator; break;
            }
        }
    }

    $root = new Root(); //Create a base instance

    $root->input = new Input(); //Add the input to the root object

    /*
    Now our base class (root) containes one object called input so we can get that at anytime by going
    */

    $root->input;

    /*
    but because root returns the input class, thats what we are now dealing with so we then can ask the input for validator function
    */

    $root->input->validate;

    /*
    Lets say in our validator class we had a class called post, witch is whats used to sanitize the post data, we then canm call that from validator aswell
    */
    $root->input->validate->post;

    /*
    All the weay down to you get to your final object in witch then you use its methods
    */

    if($root->input->validate->post->username('trim','strlen') < 0)
    {
       
    //This is an example of what you can make using this style of programming!

    Now let me finish of with describing how username('trim','strlen') Works:

    using the magic method __call() we can now pass in parameters aswell
    PHP Code: 
    class Test
    {
        function 
    __call($name,$arguments)
        {
            echo 
    $name ' Was called with the following parameters ' implode(',',$arguments);
        }
    }
    $test = new Test();

    $test->execute('startup','process','shutdown');
    // will print out " execute Was called with the following parameters startup,process,shutdown" 
    Now with the above example we can use $name to fetch a value from the class or w.e and then look threw the arguments to perform the function on the value before returned!

    IPB, use the method instead of globalisation of vars etc..

    Example of IPB

    PHP Code: 
    $salt     $this->ipsclass->converge->generate_password_salt); 
    Hope you enjoyed

    peace
    litewarez Reviewed by litewarez on . How to streamline objects in PHP! heya guys, Thought i would just do a quick tutorial on how to streamline objects in PHP! Streamlining objects creates a more organized code structure! For example $id = $root->input->validate->post->id('int') Now what this is doing is asking the $root object for the input object, and then we ask the input to give us the validate object, etc etc! So how you do this ? Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Respected Member
    This tutorial is terrible, all you've done is post 3 code snippets and you haven't even explained what the code does properly. Perhaps you should explain how to actually use "magic methods"? Rather then pasting the code and expecting us to figure it out automatically.

    Anyway, good contribution I guess, better then nothing.
    "Maybe this world is another planet's Hell"

  4.     
    #3
    Respected Developer
    Instead of posting tutorials would you mind helping JmZ code a few plugins for his auto ?

    Nice share.

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    I was in a rush to finish it, ill redo it now lool!
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    Member
    Website's:
    eih.bz pornDDL.me sexytattoochicks.tumblr.com
    You guys always give criticism. Stop crying and make a better tut? Appreciate others work

  7.     
    #6
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Its not exactly easy to find ways of describing advanced OOP to people who are still doning

    $sql = 'SELECT * FROM table WHERE id = ' . mysql_real_escape_string($_GET['id']);

    Ive updated teh post describing each magic method! and how they are used.
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  8.     
    #7
    It begins...
    Lite, I guess tis the wrong forum to post them tuts. You'd be better off at a php forum

  9.     
    #8
    Respected Member
    Quote Originally Posted by pi0tr3k View Post
    You guys always give criticism. Stop crying and make a better tut? Appreciate others work
    Nobody is crying, shut the fuck up. I appreciate his work, I could of replied with "awesome tut" like most posts in this section but I've been honest. After following my advice his tutorial is easier to read and understand which benefits everybody.

    Criticism is a good thing.
    "Maybe this world is another planet's Hell"

  10.     
    #9
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    i do agree loget

    This is a webmasters forum, PHP is the largest used language no web servers today, i believe this forum is teh perfect place to post my tutorials
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. US Govt. Objects To Megaupload Hiring Top Law Firm
    By ShareShiz in forum News & Current Events
    Replies: 2
    Last Post: 13th Apr 2012, 06:05 PM
  2. Google Strikes Back After MPAA Objects To Hotfile Intervention
    By Smith in forum News & Current Events
    Replies: 1
    Last Post: 24th Mar 2012, 03:05 AM
  3. How to add expiry date to external objects?
    By Rocke in forum Technical Help Desk Support
    Replies: 3
    Last Post: 9th May 2011, 10:57 AM
  4. [c#] variables, ifs, simple math and drawing objects
    By jayfella in forum Web Development Area
    Replies: 23
    Last Post: 18th Jun 2010, 04:52 PM

Tags for this Thread

BE SOCIAL