phpでは、プロパティ名にハイフンは使えません。が、下記のソースのように
str_relace("変換前の文字","‐","変換させたい文字がある変数")
を使うことで強制的にハイフンが利用できるみたいですが、
これは、変数を宣言するときにハイフンが使えないのであって、宣言後なら変数名に‐が使える、という認識であっておりますか。またなぜ、宣言するときに‐は使えないのでしょうか。
mymail.php
php
1class mymail { 2public $to; 3public $subject; 4public $message; 5 6private $headers = array(); 7 8public function __set($name, $value) { 9$this->headers[$name] =$value; 10} 11 12public function __get($name) { 13return $this->headers[$name]; 14} 15 16public function send() { 17foreach($this->headers as $key => $value) { 18$key = str_replace("_","-",$key); 19$others .= "{$key}:{$value}\n"; 20} 21mb_send_mail($this->to, $this->subject, $this->messagem $others); 22} 23}
php
1require_once "./mymail.php" 2$m = new maimail(); 3$m->to ="a@a.com" 4$m->subject = "題名"; 5$m->message ="内容"; 6$m->From = "s@s.com"; 7$m->X_Mailer = "MyMail 1.0"; 8$m->X_Priority = 1; 9$m->MSMail_Priority = "High"; 10$m->send(); 11
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。