Php oop!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • shushant
    replied
    Originally posted by CreativityKills View Post
    You mean spl_autoload_register
    Yes,
    sry for
    small spell error

    Leave a comment:


  • CreativityKills
    replied
    Originally posted by shushant View Post
    I Like sql_autoload_register as it is time saver
    coz does'nt need to require class in core or config file.
    Nd then starting up new instization of class
    Code:
    $clas = new class;
    to avoid it
    just simple put
    Code:
    sql_autoload_register(function($class){
    require $class.'.php';
    });
    then
    use
    Code:
    $clas = new clas;
    as it will auto require class on instization :D
    You mean spl_autoload_register

    Leave a comment:


  • shushant
    replied
    I Like sql_autoload_register as it is time saver
    coz does'nt need to require class in core or config file.
    Nd then starting up new instization of class
    Code:
    $clas = new class;
    to avoid it
    just simple put
    Code:
    sql_autoload_register(function($class){
    require $class.'.php';
    });
    then
    use
    Code:
    $clas = new clas;
    as it will auto require class on instization :D

    Leave a comment:


  • GumSlone
    replied
    Originally posted by softwarefreak View Post
    I know the use of declaring a var globally but,
    But I meant to say the same var in multiple functions, is it possible?

    function some_func()
    {
    // using $api here
    }
    function some_othr_func()
    {
    // using $api here also
    }
    yes i know that you know it, but you asked so i replied
    this will be done with global,
    or by defining a global variable like PHP: $GLOBALS - Manual or PHP: define - Manual
    in oop you have to use global too if you want to access for exaple database class

    Leave a comment:


  • softwarefreak
    replied
    Originally posted by GumSlone View Post
    PHP Code:
    $api = "4y3g3h3h3"; 

    function 
    some_func() 
    { 
    global 
    $api;
    echo 
    $api; 
    } 
    echo 
    some_func(); 
    I know the use of declaring a var globally but,
    But I meant to say the same var in multiple functions, is it possible?

    function some_func()
    {
    // using $api here
    }
    function some_othr_func()
    {
    // using $api here also
    }

    Leave a comment:


  • GumSlone
    replied
    Originally posted by softwarefreak View Post
    is this possible in php procedural programming?

    I want a variable that can be accessed inside all the functions,

    like
    PHP Code:

    $api 
    = "4y3g3h3h3";

    function 
    some_func()
    {
    echo 
    $api;
    } 
    I didn't found one so used the oo way..

    PHP Code:
    class some_class
    {
    public 
    $api = "4y3g3h3h3";

    public function 
    some_func()
    {
    echo 
    $this->api; 
    }
    } 
    PHP Code:
    $api = "4y3g3h3h3"; 

    function 
    some_func() 
    { 
    global 
    $api;
    echo 
    $api; 
    } 
    echo 
    some_func(); 

    Leave a comment:


  • vishalgzp
    replied
    main advantages
    -> Easy for dividing problems into different categorys.
    -> oop protects data much better than procedural way.
    -> Whole Data resides within classes so u can easily edit/extend it in future.
    ->Reusability (a solution of single big problem can be used while solving bigger problems)
    and NO. IT DOESNT HAS ANY SECURITY ISSUES..

    Leave a comment:


  • StunningNick
    replied
    hmm...

    Originally posted by something else View Post
    im a noob at oop ..... how do you call for a function within a function within the same class ?


    i still dont get the real advantages of using oop ....
    depends what type are you calling , possibilities are ...{PHP}
    $this->method();
    self::method();
    parent::method();
    static::method();
    ClassName::method();


    readability
    flexibility
    reusability (it's hard to explain, will try .. )
    but evil for small application

    suppose , social network application is there with following functionality ,
    picture_gallery.php
    user_list.php
    message.php



    obviously pagination is required ,
    then why not create an class with all commonly required method() rather than implementing it for every other

    both are in own ways :D bla bla bla lecture over :P
    Last edited by StunningNick; 19.03.12, 21:50. Reason: not*(no) :P

    Leave a comment:


  • something else
    replied
    i still dont get the real advantages of using oop .... i know in another topic gum mentioned being able to have similar function names but that doesnt seem to be worth it as without using oop you could have to functions one with 1 letter different in the name....
    and the other reason i have forgot .....

    i would also like to know what the dangers are of using oop:

    Originally posted by CreativityKills View Post
    OOP can be a force for both good and evil. Evil if you don't know what you're doing.
    i dont want to start coding something that can be hacked easily

    Leave a comment:


  • softwarefreak
    replied
    Originally posted by something else View Post
    im a noob at oop ..... how do you call for a function within a function within the same class ?
    :D oop is just a way to write codes differently, A person writing OOP style code may not hold the knowledge like you coding in procedural manner :P

    if you don't feel like "ohhh, the codes are so messy in my script", then carry on w/ your own way, & if yes, try OOP, I mean learn it when free ;)
    Last edited by softwarefreak; 19.03.12, 10:43. Reason: 2much LOL'ing

    Leave a comment:


  • softwarefreak
    replied
    is this possible in php procedural programming?

    I want a variable that can be accessed inside all the functions,

    like
    PHP Code:

    $api 
    = "4y3g3h3h3";

    function 
    some_func()
    {
    echo 
    $api;
    } 
    I didn't found one so used the oo way..

    PHP Code:
    class some_class
    {
    public 
    $api = "4y3g3h3h3";

    public function 
    some_func()
    {
    echo 
    $this->api; 
    }
    } 

    Leave a comment:


  • antony2kx
    replied
    Nope it does not is is very useful when creating large scale websites or classifying and modeling data Correctly, especially if you use AN OBJECT RELATIONAL DATABASE its good to use classed to model all your table data etc, a class is like a structure that can store information of the same data-type or classification.

    So it makes your code cleaner and easier to read

    Leave a comment:


  • something else
    replied
    what im a little confused about when using oop it makes your script a lot longer
    does this make it longer to process?

    Leave a comment:


  • antony2kx
    replied
    That is one way at something else

    or you can do it by extending the first class by the second one

    for example


    PHP Code:


    class Class1{

    public function 
    functionInClassOne()
    {
    echo 
    "hello worlds";
    }



    }


    class 
    Class2 extends Class1{

    public function 
    printHelloWorld()
    {
       
    $this->functionInClassOne(); //this will use the methods in class 1 because u have extended it
    }

    }

    so instance would be 

    $instance 
    = new Class2;

    $instance->printHelloWorld(); 

    as easy as it gets

    Leave a comment:


  • something else
    replied
    im guessing if you have got 2 classes then to use a function from the second class in the first class function you would use the same method as calling it outside the class?
    eg:
    PHP Code:
    <?
    class someclass{

    function function1(){
    $c = new someclass2; 
    $c->function2();
    }

    }

    class someclass2{

    funtion function2(){

    }

    }
    ?>

    Leave a comment:

Working...
X