TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-19-2008, 10:05 AM   #1 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default What do you find more comfortable?

Well I use my own framework for coding (it's time for a complete rewrite) and some of my friends use as well and I'd like the opinion of some fellow coder and what you find more comfortable using (it's also for programmers who work on my script after I deliver it to client)

methods like this
PHP Code:
<?php

$usercheck 
member::login('chuck','secret');

?>
or

PHP Code:
<?php

$member 
= new member();
$usercheck $member->login('chuck','secret');

?>
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 03-19-2008, 10:48 AM   #2 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

I find the latter example more easier.
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 03-19-2008, 03:27 PM   #3 (permalink)
The Contributor
 
dschreck's Avatar
 
Join Date: Nov 2007
Location: California
Posts: 82
Thanks: 0
dschreck is on a distinguished road
Default

in my experience, using a static method like in your first example is a lot easier and faster to type.

Usually I use static methods for carrying around instances of objects I will want. For example:
PHP Code:
$db Core::DB(); 
Returns my current instance of the database object.

I also use them for a quick authentication check:

PHP Code:
Auth::checkUser($_SESSION['Vars']['go']['Here']); 
I just find that it takes less time to type one line, and why should I create a whole new instance of an object just to run one method ?
__________________
Where I Ramble: http://www.iwilldomybest.com/
What I do: Zynga Game Network
Senior Software Engineer at CityVille
dschreck is offline  
Reply With Quote
Old 03-19-2008, 03:39 PM   #4 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

This is noobish but what does the :: do?
Gareth is offline  
Reply With Quote
Old 03-19-2008, 03:42 PM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Gareth View Post
This is noobish but what does the :: do?
It grabs a method/member from a class, such as a member would be a variable, and a method would be a function. Its just encapsulation differences. :: is a double resolution or so as double colon, in hebrew it gives you an error ( 'Paarayadim Neuktodrim' ) something rather, so many are confused at that. Anyway, its just to grab a certain method/member from a class, thats it.

PS a property is also a variable. thus either way
Update:
Gah, maybe I need to stay off the computer for 20 years.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 03-19-2008, 03:44 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

By the way, I got the OP confused, -_-.

Update: Well, my new opinion -_- Is that you should do
If the class is in the php file
PHP Code:
<?php

$usercheck 
member::login('chuck','secret');

?>
otherwise you could always do the magic method:
PHP Code:
function __autoload($php)
{
  include 
'classes/'.$php.'.php';

This grabs every single class in classes/ directory, and includes them.

Something is wrong with me today -_-
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 03-19-2008, 10:04 PM   #7 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Orc View Post
It grabs a method/member from a class, such as a member would be a variable, and a method would be a function. Its just encapsulation differences. :: is a double resolution or so as double colon, in hebrew it gives you an error ( 'Paarayadim Neuktodrim' ) something rather, so many are confused at that.
Question: what the hell are you talking about?

Quote:
Originally Posted by Orc View Post
Anyway, its just to grab a certain method/member from a class, thats it.
No, it's not. Check this out:

Code:
class Test
{
	protected $x = 2;
	
	public static function first_method()
	{
		return $this->x;
	}
	
	public static function second_method()
	{
		return 'cant use $this in static methods';
	}
	
	private static function third_method()
	{
		return 'you cant call me na na na na na';
	}
}

Test::first_method(); // Fatal error: Using $this when not in object context
Test::second_method(); // the right call
Test::third_method(); // Fatal error: Call to private method Test::third_method() from context ''
So you see, you can't just 'grab' any method/property from a class.

Tlc: it's pretty simple. Do you need an instance of a class to authenticate a user, for example? Then don't use static methods. Static methods are made for defining behavior, not functionality.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 03-19-2008, 10:13 PM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Question: what the hell are you talking about?



No, it's not. Check this out:

Code:
class Test
{
	protected $x = 2;
	
	public static function first_method()
	{
		return $this->x;
	}
	
	public static function second_method()
	{
		return 'cant use $this in static methods';
	}
	
	private static function third_method()
	{
		return 'you cant call me na na na na na';
	}
}

Test::first_method(); // Fatal error: Using $this when not in object context
Test::second_method(); // the right call
Test::third_method(); // Fatal error: Call to private method Test::third_method() from context ''
So you see, you can't just 'grab' any method/property from a class.

Tlc: it's pretty simple. Do you need an instance of a class to authenticate a user, for example? Then don't use static methods. Static methods are made for defining behavior, not functionality.
Ahh yes the static, otherwise I don't get you. Visiblity, what about it? I understand public, private, protected.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 03-20-2008, 03:08 PM   #9 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

I would suggest a bit different approach. What login should do? I suppose create a session/cookies, etc
So that's what I would prefer:

PHP Code:
$user = new Member('username','pass');
if (
$user->auth())    //checks if the password and username are correct
    
$user->login();   //sets the cookies, etc 
or maybe put the auth() part inside the login() and make it return true or false if the username/pass are correct or not.
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design