Jump to content

PHP Classes


maxudaskin

Recommended Posts

Did you read the article I linked you too? Its a 3 part series as well, just take a look at the main sites tutorials section for the rest of them.

 

I did. So the only reason to have a class is to allow for the variable to be used again without worries?

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602080
Share on other sites

Did you read the article I linked you too? Its a 3 part series as well, just take a look at the main sites tutorials section for the rest of them.

 

I did. So the only reason to have a class is to allow for the variable to be used again without worries?

 

I wouldn't say thats the only reason, but it is one of the benifits.

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602085
Share on other sites

What other benefits are there?

 

Read the articles, or do you really need one personally written here for you?

 

In this PHP.NET code, does the A::Foo not work because you are calling foo without... umm

 

-> allows for $this to be used while :: does not?

 

As for that, I have no idea what you are talking about.

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602093
Share on other sites

Sorry... didn't post the code...

 

<?php
class A
{
    function foo()
    {
        if (isset($this)) {
            echo '$this is defined (';
            echo get_class($this);
            echo ")\n";
        } else {
            echo "\$this is not defined.\n";
        }
    }
}

class B
{
    function bar()
    {
        A::foo();
    }
}

$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602094
Share on other sites

This guy is obviously a wind up.  I could write a book on benefits of object oriented programming, and I'm new to the idea, since only dabbling since September 2007.

 

But it's late, and what's the point when this guy will find some way to shoot whatever I write, out the sky anyway. Hehe

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602193
Share on other sites

It's natural to be confused, as programming is.  But honestly, if you look at those articles, as provided by the moderator, they are pretty much the simplest explanation I have seen to OOP PHP.

 

I admit yes, it is confusing, I get confused with inheritance, abstraction and bits like that, but the basic concept of classes is very, very simple.  Just take a very simple example...

 

You have a mobile phone, I presume.  Imagine a class called MobilePhone.  This can be "instantiated" by writing

$myPhone = new MobilePhone()

.  You now have an object, assigned to $myPhone (a variable in PHP, I'm sure you'll know).

 

You could now perform methods, which belong in that class, such as

$myPhone->dial(123);

or

$myPhone->sendsms(...);

and so on.

 

Classes, I think, are just a way of organising things.  I apologise if any syntax I've provided here is incorrect.  This is a bit rushed.  But seriously, those articles cover it all.

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602201
Share on other sites

So lets say I have three functions in a class: login.

 

$login = new login;

 

When someone goes to the login page, it will check if logged in:

 

if($login->checkLoggedin)

checkLoggedin returns false

 

How could I call a function in a class?

 

if($login->checkLoggedin){
    $login->displayForm; // Call the function... somehow
}

Link to comment
https://forums.phpfreaks.com/topic/117058-php-classes/#findComment-602205
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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