php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9195 Allow this be passed as default class function parameter
Submitted: 2001-02-09 13:00 UTC Modified: 2011-11-18 06:23 UTC
Votes:9
Avg. Score:4.6 ± 0.7
Reproduced:8 of 8 (100.0%)
Same Version:1 (12.5%)
Same OS:3 (37.5%)
From: nathan at cjhunter dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: * OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nathan at cjhunter dot com
New email:
PHP Version: OS:

 

 [2001-02-09 13:00 UTC] nathan at cjhunter dot com
I'm requesting that the default function arguments for a class method be able to reference the class variable members in it's definition. 

Here is an example of it's use:

class searchclass {

	var $hits;
	var $results;

	function save($filename, $start = 0, $end = $this->hits){ /* <- this returns Parse error: */
		if($fp = @fopen($filename, "w")){
			for($i = $start; $i < $end; $i++){
				fwrite($fp, implode("|", $this->results[$i]));
			}
		}else{
			return false;
		}
	}

	function search(){
		/* ... */
	}

}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-01 15:55 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2010-12-01 15:58 UTC] jani@php.net
-Summary: Default class function arguments +Summary: Allow this be passed as default class function parameter -PHP Version: 4.0.2 +PHP Version: *
 [2011-07-06 11:29 UTC] laruence@php.net
$this is in execute process, function declaring is in compile process, 
but you can use a compiling variable:

class A {
   const FOO = 2;
   public function dummy($a = FOO) {
   }
}
 [2011-07-06 11:31 UTC] laruence@php.net
sorry for misspell:
class A {
   const FOO=2;
   public function dummy($a = self::FOO) {
   }
}
 [2011-11-18 06:23 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2011-11-18 06:23 UTC] laruence@php.net
-Status: Analyzed +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC