PHP friend-লাইক ডিক্লেয়ারেশন সাপোর্ট করে না। এটি PHP5-এ __get এবং __set মেথড এবং আলোয়েড ফ্রেন্ড ক্লাসের জন্য ব্যাকট্রেস ইনসপেক্ট করে সিমুলেট করা যায়। কিন্তু এই ধরনের কোডিং প্র্যাকটিস ক্লান্তিকর বলে মনে করা হয়:
class sample_friend { private $__friends = array('My_Friend', 'Other_Friend'); public function __get($key) { $trace = debug_backtrace(); if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) { return $this->$key; } // __get() কোড যায় এখানে trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR); } public function __set($key, $value) { $trace = debug_backtrace(); if(isset($trace[1]['class']) && in_array($trace[1]['class'], $this->__friends)) { return $this->$key = $value; } // সাধারণ __set() কোড যায় এখানে trigger_error('Cannot access private property ' . __CLASS__ . '::$' . $key, E_USER_ERROR); } }