29-12-2007, 09:55
|
|
|
|
חבר מתאריך: 01.05.06
הודעות: 7,861
|
|
פונקציה במחלקה אבסטרקטית שמסרבת לתפקד בגלל פיסת קוד.
רציתי קצת לתרגל OOP ועל הדרך ללמוד יותר לעומק GD.
יצרתי מחלקה ל GD ועוד מחלקה בשם aGD שתהיה אבסטרקטית.
ניסיתי ליצור מתודה משותפת בתוך ה מחלקה האבסטרקטית ובה "להרוס" את התמונה (זה לא עניין של יעילות, אלא תרגול).
הקוד הבא עובד מצויין:
קוד PHP:
<?php
abstract class aGD { abstract public function __construct(); // obtains the image link from the inscription abstract protected function run(); // executes the image code // destroys the image public function destroy() { die('works'); } } class GD extends aGD { protected $image, $type, $resource; public function __construct() { $this->run(); } protected function run() { } } $GD = new GD; $GD->destroy(); ?>
הפלט הוא works.
אבל כשיש לי את הקוד הבא בתוך ה run הפונקציה destroy מפסיקה להיקרא ולא משנה מה אני מכניס לתוכה היא לא מגיבה.
הקוד המלא:
https://2007-uploaded.fresh.co.il/2...9/37062325.phps
קוד PHP:
<?php
abstract class aGD { abstract public function __construct(); // obtains the image link from the inscription abstract protected function run(); // executes the image code // destroys the image public function destroy() { die('works'); imagedestroy($this->resource); } } class GD extends aGD { protected $image, $type, $resource; public function __construct() { $this->image = addslashes(trim($_GET['images'])); $this->run(); } protected function run() { if (preg_match("/^http:\/\/.+\..+\.(gif|jpg|jpeg|png)$/i", trim($this->image))) { $this->type = str_replace('jpg', 'jpeg', array_pop(explode('.', $this->image))); header('Content-type: image/'.$this->type); $this->resource = @call_user_func('imagecreatefrom'.$this->type, $this->image); if (!is_resource($this->resource)) die('Invalid image link was given'); call_user_func('image'.$this->type, $this->resource); } else { die('Invalid image link was given'); } } } $GD = new GD; $GD->destroy(); ?>
מציג לי את התמונה כמו שצריך ולא משנה מה אני עושה destroy לא מגיב.
כלומר, עצם קיומה של התמונה גורמת לdestroy להפסיק לתפקד, אפילו אם אני מכניס לתוכה פונקציה שלא קיימת לא מוצגת לי שגיאה.
למישהו יש מושג מה הולך כאן?
תודה מראש.
נערך לאחרונה ע"י netaneldj בתאריך 29-12-2007 בשעה 09:59.
|