Php oop!

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

31 replies · 1,854 views · started 14 years ago · 1 min read

11 participants
antony2kx Developer · 94 posts #21

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

softwarefreak Senior · 349 posts #22

is this possible in php procedural programming?

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

like

$api = "4y3g3h3h3";

function some_func()
{
echo $api;
}

I didn't found one so used the oo way..

class some_class
{
public $api = "4y3g3h3h3";

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

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

softwarefreak Senior · 349 posts #23

something else wrote: im a noob at oop ..... how do you call for a function within a function within the same class ?

😀 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 😛

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 😉

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

something else Fellow · 2,296 posts #24

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:

CreativityKills wrote: 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

StunningNick Junior · 40 posts #25

hmm...

something else wrote: 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 😀 bla bla bla lecture over 😛

Don't think i am bad , i used to be too good one time...

vishalgzp Junior · 24 posts #26

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..

ADD YOUR SITES TO WAP.VISHWAP.COM

GumSlone Administrator Principal · 1,690 posts #27

softwarefreak wrote: is this possible in php procedural programming?

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

like

$api = "4y3g3h3h3";

function some_func()
{
echo $api;
}

I didn't found one so used the oo way..

class some_class
{
public $api = "4y3g3h3h3";

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

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

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

softwarefreak Senior · 349 posts #28

GumSlone wrote:

$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 }

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

GumSlone Administrator Principal · 1,690 posts #29

softwarefreak wrote: 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

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

shushant Developer · 207 posts #30

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

$clas = new class;

to avoid it just simple put

sql_autoload_register(function($class){
require $class.'.php';
});

then use

$clas = new clas;

as it will auto require class on instization 😀

CreativityKills Lead · 833 posts #31

shushant wrote: 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

$clas = new class;

to avoid it just simple put

sql_autoload_register(function($class){
require $class.'.php';
});

then use

$clas = new clas;

as it will auto require class on instization :D

You mean spl_autoload_register

Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close