Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 05:57

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[PHP] in_array für Objekte mit getter Funktionen

Discussion on [PHP] in_array für Objekte mit getter Funktionen within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1


 
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
[PHP] in_array für Objekte mit getter Funktionen

Da PHP doch sehr limitiert ist und anscheinend auch nicht viel Wert auf Sicherheit in Bezug auf Zugriffskontrolle legt, muss natürlich auch ne Funktion dafür her.

Code:
// Checks if a particular value (needle) is present in an array (haystack).
// Calls the specified object function (needle_method) dynamically in order to query object attributes via getters
function in_array_method($needle, $needle_method, $haystack, $strict = false)
{ 
    if ($strict)
	{ 
        foreach ($haystack as $item) 
		{
			$value = $item->{$needle_method}();
            if (isset($value) && $value === $needle) 
                return true; 
		}
    } 
    else 
	{ 
        foreach ($haystack as $item)
		{
			$value = $item->{$needle_method}();
            if (isset($value) && $value == $needle) 
                return true; 
		}
    } 
    return false; 
}
Meine Funktion basiert auf der Version von Lea Hayes (), die aber nur auf Attribute mit public modifier zugreifen kann.

Code:
class Testclass
{
	public function __construct($id)
	{
		$this->_ID = $id;
	}
	
	public function GetID() { return $this->_ID; }
	private $_ID;
}
Durch den private modifier ist ein Zugriff auch über die in_array Funktion nicht möglich, daher muss ein getter (in diesem Fall GetID()) spezifiziert werden, damit die Funktion auch darauf zugreifen kann.

Code:
$testarr = array(new Testclass(5), new Testclass(6));
Code:
in_array_method("6", "GetID", $testarr); // true
in_array_method("5", "GetID", $testarr); // true
in_array_method("7", "GetID", $testarr); // false
Mostey is offline  
Thanks
3 Users
Reply


Similar Threads Similar Threads
SID and UID Getter by Requi ^.^
01/29/2013 - DarkOrbit - 23 Replies
So Guys. Because I haven't anything to do I modified my Basic Login Script :p Here you can put your Data in and you'll get a ".txt", where your SID and UID is placed :awesome: PLEASE don't press often than once the Login Button. Thanks :) Now faster than lightspeed :D Download AutoIt Version:
glob() und in_array()
12/18/2012 - Web Development - 2 Replies
Ich möchte mit glob() ein array der Dateien ausgeben, sie dan mit in_array überprüfen ich bekomme das aber nicht so hin. glob($filePath."*.php"); Ich kann es ja in ner foreach schleife auslesen aber wie soll ich das dan da einbinden:
[Release]duffbier`s D3D NoMenu Base [D3D Funktionen/Normale Funktionen]
06/01/2011 - WarRock Hacks, Bots, Cheats & Exploits - 15 Replies
Hey Com. Ich hab mich entschieden meine D3D NoMenu Base zu Releasen In dieser kannst du normale Funktionen sowie D3D Funktionen adden Screens: http://img64.imageshack.us/img64/4444/screeenl.jp g
°*NEW Funktionen*° th3man0f22 NO MENÜ Public Hack°*NEW Funktionen*° 06.09.2010
09/06/2010 - WarRock Hacks, Bots, Cheats & Exploits - 2 Replies
Funktionen: PLAYERPOINTER ¤SERVERPOINTER (Immer an)¤ ¤NOSPREAD (Numm-Pad 7)¤ ¤FULLBRIGHT (Numm-Pad 5)¤ ¤EXTRAAMMO1 (Immer an)¤ ¤EXTRAAMMO2 (Immer an)¤ ¤SCOPE (Rechte Maustaste)¤ ¤FASTAMMO (Immer an)¤



All times are GMT +1. The time now is 05:58.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.